Part of twisted.python.threadpool View Source View In Hierarchy
callInThread
and stop
should only be called from a single thread, unless you make a subclass
where stop
and _startSomeWorkers
are synchronized.
Instance Variable | started | Whether or not the thread pool is currently running. (type: bool ) |
Instance Variable | threads | List of workers currently running in this thread pool. (type: list ) |
Method | __init__ | Create a new threadpool. |
Method | start | Start the threadpool. |
Method | startAWorker | Undocumented |
Method | stopAWorker | Undocumented |
Method | __setstate__ | Undocumented |
Method | __getstate__ | Undocumented |
Method | callInThread | Call a callable object in a separate thread. |
Method | callInThreadWithCallback | Call a callable object in a separate thread and call
onResult with the return value, or a twisted.python.failure.Failure
if the callable raises an exception. |
Method | stop | Shutdown the threads in the threadpool. |
Method | adjustPoolsize | Undocumented |
Method | dumpStats | Undocumented |
Method | _startSomeWorkers | Undocumented |
Method | _workerState | Manages adding and removing this worker from a list of workers in a particular state. |
Method | _worker | Method used as target of the created threads: retrieve a task to run from the threadpool, run it, and proceed to the next task until threadpool is stopped. |
Parameters | minthreads | minimum number of threads in the pool |
maxthreads | maximum number of threads in the pool |
Parameters | func | callable object to be called in separate thread |
*args | positional arguments to be passed to func | |
**kw | keyword args to be passed to func |
onResult
with the return value, or a twisted.python.failure.Failure
if the callable raises an exception.
The callable is allowed to block, but the onResult
function
must not block and should perform as little work as possible.
A typical action for onResult
for a threadpool used with a
Twisted reactor would be to schedule a twisted.internet.defer.Deferred
to fire in the main reactor thread using .callFromThread
.
Note that onResult
is called inside the separate thread, not
inside the reactor thread.
Parameters | onResult | a callable with the signature (success, result) . If the
callable returns normally, onResult is called with
(True, result) where result is the return value
of the callable. If the callable throws an exception, onResult
is called with (False, failure) .
Optionally, |
func | callable object to be called in separate thread | |
*args | positional arguments to be passed to func | |
**kwargs | keyword arguments to be passed to func |
Parameters | stateList | the list managing workers in this state |
workerThread | the thread the worker is running in, used to represent the worker in stateList |