timer

Standalone implementation of time-out check on function call. Timer stops execution of wrapped function if it reaches the limit of provided time. Supports decorator feature.

author:

Alexey Anisenkov

contact:

anisyonk@cern.ch

date:

March 2018

class pilot.util.timer.TimedProcess(timeout)[source]

Process-based Timer implementation (multiprocessing module). Uses shared Queue to keep result. (completely isolated memory space) In default python implementation multiprocessing considers (c)pickle as serialization backend which is not able properly (requires a hack) to pickle local and decorated functions (affects Windows only) Traceback data is printed to stderr

__dict__ = mappingproxy({'__module__': 'pilot.util.timer', '__doc__': '\n        Process-based Timer implementation (`multiprocessing` module). Uses shared Queue to keep result.\n        (completely isolated memory space)\n        In default python implementation multiprocessing considers (c)pickle as serialization backend\n        which is not able properly (requires a hack) to pickle local and decorated functions (affects Windows only)\n        Traceback data is printed to stderr\n    ', '__init__': <function TimedProcess.__init__>, 'run': <function TimedProcess.run>, '__dict__': <attribute '__dict__' of 'TimedProcess' objects>, '__weakref__': <attribute '__weakref__' of 'TimedProcess' objects>, '__annotations__': {}})
__init__(timeout)[source]
Parameters:

timeout – timeout value for operation in seconds.

__module__ = 'pilot.util.timer'
__weakref__

list of weak references to the object (if defined)

run(func, args, kwargs, timeout=None)[source]
class pilot.util.timer.TimedThread(timeout)[source]

Thread-based Timer implementation (threading module) (shared memory space, GIL limitations, no way to kill thread, Windows compatible)

__dict__ = mappingproxy({'__module__': 'pilot.util.timer', '__doc__': '\n        Thread-based Timer implementation (`threading` module)\n        (shared memory space, GIL limitations, no way to kill thread, Windows compatible)\n    ', '__init__': <function TimedThread.__init__>, 'execute': <function TimedThread.execute>, 'run': <function TimedThread.run>, '__dict__': <attribute '__dict__' of 'TimedThread' objects>, '__weakref__': <attribute '__weakref__' of 'TimedThread' objects>, '__annotations__': {}})
__init__(timeout)[source]
Parameters:

timeout – timeout value for operation in seconds.

__module__ = 'pilot.util.timer'
__weakref__

list of weak references to the object (if defined)

execute(func, args, kwargs)[source]
run(func, args, kwargs, timeout=None)[source]
Raise:

TimeoutException if timeout value is reached before function finished

exception pilot.util.timer.TimeoutException(message, timeout=None, *args)[source]
__init__(message, timeout=None, *args)[source]
__module__ = 'pilot.util.timer'
__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

pilot.util.timer.Timer

alias of TimedProcess

pilot.util.timer.timeout(seconds, timer=None)[source]

Decorator for a function which causes it to timeout (stop execution) once passed given number of seconds. :param timer: timer class (by default is Timer) :raise: TimeoutException in case of timeout interrupt