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

Methods

now

time() -> floating point number

signal_handler(_signum, _frame)

raise TimeoutError.

time_elapsed()

returns time elapsed since entering the context.

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.