aea.helpers.exec_
timeout
Python code execution time limit tools.
TimeoutResult Objects
Result of ExecTimeout context manager.
__
init__
Init.
set_
cancelled_
by_
timeout
Set code was terminated cause timeout.
is_
cancelled_
by_
timeout
Return True if code was terminated by ExecTimeout cause timeout.
Returns:
bool
TimeoutException Objects
TimeoutException raised by ExecTimeout context managers in thread with limited execution time.
Used internally, does not propagated outside of context manager
BaseExecTimeout Objects
Base class for implementing context managers to limit python code execution time.
exception_class - is exception type to raise in code controlled in case of timeout.
__
init__
Init.
Arguments:
timeout
: number of seconds to execute code before interruption
__
enter__
Enter context manager.
Returns:
TimeoutResult
__
exit__
Exit context manager.
Arguments:
exc_type
: the exception typeexc_val
: the exceptionexc_tb
: the traceback
ExecTimeoutSigAlarm Objects
ExecTimeout context manager implementation using signals and SIGALARM.
Does not support threads, have to be used only in main thread.
ExecTimeoutThreadGuard Objects
ExecTimeout context manager implementation using threads and PyThreadState_SetAsyncExc.
Support threads. Requires supervisor thread start/stop to control execution time control. Possible will be not accurate in case of long c functions used inside code controlled.
__
init__
Init ExecTimeoutThreadGuard variables.
Arguments:
timeout
: number of seconds to execute code before interruption
start
Start supervisor thread to check timeouts.
Supervisor starts once but number of start counted.
stop
Stop supervisor thread.
Actual stop performed on force == True or if number of stops == number of starts
Arguments:
force
: force stop regardless number of start.