Module threadpool :: Class WorkRequest
[frames] | no frames]

Class WorkRequest

source code

A request to execute a callable for putting in the request queue later.

See the module function makeRequests for the common case where you want to build several WorkRequest objects for the same callable but with different arguments for each call.

Instance Methods
 
__init__(self, callable_, args=None, kwds=None, requestID=None, callback=None, exc_callback=<function _handle_thread_exception at 0x7f4c990347d0>)
Create a work request for a callable and attach callbacks.
source code
 
__str__(self) source code
Method Details

__init__(self, callable_, args=None, kwds=None, requestID=None, callback=None, exc_callback=<function _handle_thread_exception at 0x7f4c990347d0>)
(Constructor)

source code 

Create a work request for a callable and attach callbacks.

A work request consists of the a callable to be executed by a worker thread, a list of positional arguments, a dictionary of keyword arguments.

A callback function can be specified, that is called when the results of the request are picked up from the result queue. It must accept two anonymous arguments, the WorkRequest object and the results of the callable, in that order. If you want to pass additional information to the callback, just stick it on the request object.

You can also give custom callback for when an exception occurs with the exc_callback keyword parameter. It should also accept two anonymous arguments, the WorkRequest and a tuple with the exception details as returned by sys.exc_info(). The default implementation of this callback just prints the exception info via traceback.print_exception. If you want no exception handler callback, just pass in None.

requestID, if given, must be hashable since it is used by ThreadPool object to store the results of that work request in a dictionary. It defaults to the return value of id(self).