Package jazzparser :: Package utils :: Module multiproc
[hide private]
[frames] | no frames]

Module multiproc

source code

Multiprocessing utilities.


Author: Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>

Classes [hide private]
  Result
Functions [hide private]
 
timeout(fun, *args, **kwargs)
Decorator that applies a function with the given args and kwargs, enforcing a timeout.
source code
Variables [hide private]
  __package__ = 'jazzparser.utils'
Function Details [hide private]

timeout(fun, *args, **kwargs)

source code 

Decorator that applies a function with the given args and kwargs, enforcing a timeout. Blocks until the function completes or the timeout expires. If the timeout expires, raises a TimeoutError.

The intended use of this is to submit a job to a multiprocessing pool with a timeout, after which the whole processing terminates. This only makes sense if you have just one task per process or set maxtasksperchild=1 on the pool.

Note: the function execution does not actually halt when the exception is raised, but continues in another thread. There is no way to terminate this thread from outside it.