Feature to constrain computation time?

26 views
Skip to first unread message

Szabolcs Horvát

unread,
Sep 2, 2019, 7:46:15 AM9/2/19
to sage-support
Does Sage have a feature to constrain computation time? Suppose the function f() takes a long time to run. I am looking for a way to run it *for at most 5 minutes*. If it finishes by then, I'd like to have the return value from f(). If not, it should communicate that clearly, and the system should be ready for the next computation.

For those familiar with Mathematica, I am looking for something similar to its TimeConstrained[] command.

slelievre

unread,
Sep 2, 2019, 8:55:41 AM9/2/19
to sage-support
You could use `alarm`, see

- Ask Sage question 7931 - Any way to timeout?

Jori Mäntysalo (TAU)

unread,
Sep 2, 2019, 2:08:40 PM9/2/19
to sage-support
On Mon, 2 Sep 2019, Szabolcs Horvát wrote:

> Does Sage have a feature to constrain computation time? Suppose the function
> f() takes a long time to run. I am looking for a way to run it *for at most
> 5 minutes*.

I think it has. But what if you just use timeout from command line? I.e.

timeout $((5*60)) ./sage my_script.sage

--
Jori Mäntysalo

Tampereen yliopisto - Ihminen ratkaisee
Reply all
Reply to author
Forward
0 new messages