how to run an arbitrary function with timeout?

Tony C cappy2112 at yahoo.com
Mon May 17 21:37:12 EDT 2004


jbore at tjtech.com (Joseph T. Bore) wrote in message news:<m31xljkwjc.fsf at union.tjtech.com>...
> Mark Day <mday at apple.com> writes:
> > In article <2004051413541084557280 at k2.sage.att.com>, Garry Hodgson
> > <garry at sage.att.com> wrote:
> import signal
> 
> #
> # a alarm signal handler
> #
> def alarmHandler(signum, frame):
>     raise TimeExceededError, "Your command ran too long"
> 
> #
> # a function that would run for too long
> #
> def infinite():
>     while 1:
>         pass
>     return
> 
> #
> # set the alarm signal handler, and set the alarm to 1 second
> #
> signal.signal(signal.SIGALRM, alarmHandler)
> signal.alarm(1)

This is a very interesting solution.
However, signal.alarm() and signal.SIGALRM are not defined in my signal module
I'm using 2.3.3



More information about the Python-list mailing list