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.