xoutil.threading – Higher-level threading interface

xoutil.threading.async_call(func, args=None, kwargs=None, callback=None, onerror=None)[source]

Executes a function func with the given positional and keyword arguments asynchronously.

If callback is provided, it is called with a single positional argument: the result of calling func(*args, **kwargs).

If the called function ends with an exception and onerror is provided, it is called with the exception object.

Returns:An event object that gets signalled when the function ends its execution whether normally or with an error.
Return type:threading.Event
xoutil.threading.sync_call(funcs, callback, timeout=None)[source]

Calls several functions each in it’s own thread, and waits for all to end.

Each time a function ends the callback is called (wrapped in a lock to avoid race conditions) with the result of the as a single positional argument.

If timeout is not None it sould be a float number indicading the seconds to wait before aborting. Functions that terminated before the timeout will have called callback, but those that are still working will be ignored.

Todo

Abort the execution of a thread.

Parameters:funcs – A sequences of callables that receive no arguments.