xotl.tools.future.threading - Higher-level threading interface¶
This module extends the standard library’s threading. You may use it
as a drop-in replacement in many cases.
Avoid importing * from this module since could be different in Python 2.7
and Python 3.3.
We added the following features.
-
xotl.tools.future.threading.async_call(func, args=None, kwargs=None, callback=None, onerror=None)[source]¶ Executes a function asynchronously.
The function receives the given positional and keyword arguments
If
callbackis provided, it is called with a single positional argument: the result of callingfunc(*args, **kwargs).If the called function ends with an exception and
onerroris 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: Event
-
xotl.tools.future.threading.sync_call(funcs, callback, timeout=None)[source]¶ Calls several functions, each one in it’s own thread.
Waits for all to end.
Each time a function ends the
callbackis called (wrapped in a lock to avoid race conditions) with the result of the as a single positional argument.If
timeoutis not None it sould be a float number indicading the seconds to wait before aborting. Functions that terminated before the timeout will have calledcallback, 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.