If you want to tweak this, it might be helpful to look at the signal
module in python, which is presumably what the above alarm function
uses; a helpful example is at:

http://docs.python.org/lib/node545.html

...and the parent documentation to that has all the details.

-M. Hampton

On May 26, 6:54 pm, Andrey Novoseltsev <[EMAIL PROTECTED]> wrote:
> Thank you, that's exactly what I need!
>
> Andrey
>
> On May 26, 4:46 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
>
> > On Mon, May 26, 2008 at 4:38 PM, Andrey Novoseltsev <[EMAIL PROTECTED]> 
> > wrote:
>
> > > Is there any way to automatically terminate the current computation if
> > > it takes longer than given amount of time (say, a minute)? I want it
> > > to be inside a loop that will stop some iterations and continue, if
> > > they are taking too long.
>
> > Yes, I wrote something to do this a long time ago.
> > Use the alarm command:
>
> > {{{id
> > alarm(3)
> > for i in range(10):
> >     print i
> >     sleep(1)
> > ///
>
> > 0
> > 1
> > 2
> > Traceback (most recent call last):        sleep(1)
> >   File "/Users/was/s/local/lib/python2.5/site-packages/sympy/plotting/",
> > line 3, in <module>
>
> >   File "/Users/was/s/local/lib/python2.5/site-packages/sage/misc/misc.py",
> > line 1345, in __mysig
> >     raise KeyboardInterrupt, "computation timed out because alarm was
> > set for %s seconds"%__alarm_time
> > KeyboardInterrupt: computation timed out because alarm was set for 3 seconds
>
> > }}}- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to