Stop long-running function

42 views
Skip to first unread message

Paul Royik

unread,
Feb 20, 2015, 5:53:27 PM2/20/15
to sy...@googlegroups.com
Is there any way to stop long running function?

Simplify sometimes runs too long.
I want to terminate it after 30 seconds.


Thank you.

Jason Moore

unread,
Feb 20, 2015, 6:08:10 PM2/20/15
to sy...@googlegroups.com
<ctrl>-C will terminate a running command.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/31c4c890-02c3-4872-b41b-8432b0a90c20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Royik

unread,
Feb 20, 2015, 6:12:05 PM2/20/15
to sy...@googlegroups.com
I mean in program, not in command window.

Jason Moore

unread,
Feb 20, 2015, 6:38:14 PM2/20/15
to sy...@googlegroups.com

Sudhanshu Mishra

unread,
Feb 20, 2015, 6:59:48 PM2/20/15
to sy...@googlegroups.com
Perhaps this would be a good addition to functions like `solve`, `simplify`, `integrate`, etc. A parameter, maybe `max_time`, would take no. of seconds as input and stop the respective execution when it hits the max.

Aaron Meurer

unread,
Feb 20, 2015, 7:00:57 PM2/20/15
to sy...@googlegroups.com

Sudhanshu Mishra

unread,
Feb 20, 2015, 7:12:02 PM2/20/15
to sy...@googlegroups.com
Great! I never saw this PR. There's not much discussion about it there.

Joachim Durchholz

unread,
Feb 21, 2015, 3:56:07 AM2/21/15
to sy...@googlegroups.com
Am 21.02.2015 um 00:37 schrieb Jason Moore:
> Maybe this:
> http://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-python

The caveat is important: "Not sure how cross-platform that is."
AFAIK signals and alarms do not work under Windows.

You can move the function call into a separate process and kill the
subprocess if it takes too long. I know of no readymade recipe for that,
except that one could extract it from SymPy's testing framework which
does exactly this.

The other approach would be to use multithreading, but that's not an
option for CPython (too fragile, interpreter isn't really built for
that); one could use that in Jython, Stackless, or probably pypy, and
even then, there are things that won't get cleaned up properly if one
thread interrupts another.

Joachim Durchholz

unread,
Feb 21, 2015, 3:58:23 AM2/21/15
to sy...@googlegroups.com
Am 21.02.2015 um 01:00 schrieb Aaron Meurer:
> See also https://github.com/sympy/sympy/pull/8297 and
> https://github.com/sympy/sympy/pull/8295.

Cooperative checking, while intrusive, is the least fragile option IMNSHO.

Paul Royik

unread,
Feb 21, 2015, 5:32:44 AM2/21/15
to sy...@googlegroups.com
So, this feature is closed?

Joachim Durchholz

unread,
Feb 21, 2015, 9:45:49 AM2/21/15
to sy...@googlegroups.com
Am 21.02.2015 um 11:32 schrieb Paul Royik:
> So, this feature is closed?

We'd really like to have that, we're just not sure how to implement it.

Paul Royik

unread,
Feb 21, 2015, 11:18:38 AM2/21/15
to sy...@googlegroups.com
I see.
Reply all
Reply to author
Forward
0 new messages