PlasmaCalcs.tools.timing.TimeLimit

class PlasmaCalcs.tools.timing.TimeLimit(seconds)

Bases: object

context manager which imposes a time limit, exiting with TimeoutError if internal code takes too long.
Usage example:
with TimeLimit(10):
# any code in this block must complete within 10 seconds, else will crash with TimeoutError.
seconds: None or int
timeout after this many seconds (unless code completes before then).
Must be an integer, due to limitations of signal.alarm method.
None, or <=0 –> no time limit
__init__(seconds)

Methods

__init__(seconds)

now

signal_handler(_signum, _frame)

time_elapsed()

static now()
time() -> floating point number
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
signal_handler(_signum, _frame)
raise TimeoutError.
time_elapsed()
returns time elapsed since entering the context.