eg.ThreadWorker¶
-
class
eg.
ThreadWorker
(*args, **kwargs)[source]¶ General purpose message pumping thread, that is used in many places.
-
Call
(func, *args, **kwargs)[source]¶ Queue a function and its arguments for execution in the
eg.ThreadWorker
thread. Doesn’t wait for the completion of the function.
-
CallWait
(func, timeout=10.0)[source]¶ Queue a function for execution in the
eg.ThreadWorker
thread. Waits for completion of the function and returns its result.The function must have no arguments, so if some are needed one should create a argumentless function with functools.partial.
Note
This function is deprecated. Use the
Func()
wrapper instead.
-
Finish
()[source]¶ This will be called inside the thread when it finishes. It will even be called if the thread exits through an exception.
-
Func
(func, timeout=None)[source]¶ Wraps a function for synchronized execution in the
eg.ThreadWorker
thread.The returned object can be called like the unwrapped function but will execute in the
eg.ThreadWorker
thread regardless were it is called from. The call will deliver the return value of the function. If the function raises an exception, it will be propagated to the calling thread.The optional timeout value specifies the maximal time to wait for the completion of the function in floating point seconds. If the timeout expires, the call will raise an exception. If timeout is not specified or None (the default), it will wait forever.
Example usage:
threadWorker = eg.ThreadWorker() threadWorker.Start() def MyFunction(param): print param return "Hello Caller!" wrappedFunc = threadWorker.Func(MyFunction, 5.0) result = wrappedFunc("Hello World!") print result
-
Setup
(*args, **kwargs)[source]¶ This will be called inside the thread at the beginning.
Any exception raised in this method will be propagated to the
Start()
method and re-raised there.
-
Start
(timeout=None)[source]¶ Start the thread execution.
The thread will first call the self.Setup method with the parameters assigned by the
eg.ThreadWorker
constructor and waits tillSetup()
has finished its execution. If an exception is raised in self.Setup, this exception will be propagated to the self.Start method, so it will look like self.Start has directly calledSetup()
. ButSetup()
is actually executed in the new thread.
-