timeout¶
Class summary¶
RunableProcessing (func, *args, **kwargs) |
Attributes |
TimeoutException |
Function summary¶
_longcos (x[, wait]) |
calc cos(x) after waiting wait seconds. max wait is 5 seconds |
timeout (seconds[, force_kill]) |
Module listing¶
Code to timeout with processes.
References¶
Code in this module comes from an activestate code recipe [R99]. For an asynchronous solution see the active activestate code recipe [R100].
[R99] | timeout decorator (with multiprocessing) (Python recipe) synchronous |
[R100] | Timeout Any Function (Python recipe) asynchronous |
Examples¶
>>> timed_longcos = timeout(2)(_longcos)
>>> timed_longcos(1, 0)
0.5403...
>>> timed_longcos(1, 2)
Traceback (most recent call last):
...
TimeoutException: timed out after 2 seconds
Notes¶
The following examples from the original activestate code recipe demonstrate how to use timeout as a decorator. They don’t seem to work for me as the functions must be defined in __main__ to be pickled. you get the idea though.
@timeout(.5)
def sleep(x):
print "ABOUT TO SLEEP {0} SECONDS".format(x)
time.sleep(x)
return x
sleep(1)
Traceback (most recent call last):
...
TimeoutException: timed out after 0 seconds
sleep(.2)
0.2
@timeout(.5)
def exc():
raise Exception('Houston we have problems!')
exc()
Traceback (most recent call last):
...
Exception: Houston we have problems!
-
class
geotecha.inputoutput.timeout.
RunableProcessing
(func, *args, **kwargs)[source]¶ Bases:
multiprocessing.process.Process
Attributes
authkey
daemon
Return whether process is a daemon exitcode
Return exit code of process or None if it has yet to stop ident
Return identifier (PID) of process or None if it has yet to start name
pid
Return identifier (PID) of process or None if it has yet to start Methods
done
()is_alive
()Return whether process is alive join
([timeout])Wait until child process terminates result
()run
()Method to be run in sub-process; can be overridden in sub-class run_func
(func, *args, **kwargs)start
()Start child process terminate
()Terminate process; sends SIGTERM signal or uses TerminateProcess()