This class (hopefully) generalizes the functionality of a pool of threads to which work can be dispatched.
callInThread
and stop
should only be called from a single thread.
Method | __getstate__ |
Undocumented |
Method | __init__ |
Create a new threadpool. |
Method | __setstate__ |
Undocumented |
Method | adjust |
Adjust the number of available threads by setting min and max to new values. |
Method | call |
Call a callable object in a separate thread. |
Method | call |
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 | dump |
Dump some plain-text informational messages to the log about the state of this ThreadPool . |
Method | start |
Start the threadpool. |
Method | start |
Increase the number of available workers for the thread pool by 1, up to the maximum allowed by ThreadPool.max . |
Method | stop |
Shutdown the threads in the threadpool. |
Method | stop |
Decrease the number of available workers by 1, by quitting one as soon as it's idle. |
Class Variable | current |
Undocumented |
Instance Variable | joined |
Undocumented |
Instance Variable | max |
Undocumented |
Instance Variable | min |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | started |
Whether or not the thread pool is currently running. |
Instance Variable | threads |
List of workers currently running in this thread pool. |
Property | waiters |
For legacy compatibility purposes, return the number of idle workers as expressed by a list the length of that number. |
Property | workers |
For legacy compatibility purposes, return a total number of workers. |
Property | working |
For legacy compatibility purposes, return the number of busy workers as expressed by a list the length of that number. |
Method | _generate |
Generate a name for a new pool thread. |
Instance Variable | _pool |
A hook for testing. |
Instance Variable | _team |
Undocumented |
Property | _queue |
For legacy compatibility purposes, return an object with a qsize method that indicates the amount of work not yet allocated to a worker. |
Adjust the number of available threads by setting min and max to new values.
Parameters | |
minthreads:int | None | The new value for ThreadPool.min . |
maxthreads:int | None | The new value for ThreadPool.max . |
Callable[ [ bool, _R], object] | None
, func: Callable[ _P, _R]
, *args: _P.args
, **kw: _P.kwargs
):
(source)
¶
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.
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 | |
onCallable[ | 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, onResult may be |
func:Callable[ | callable object to be called in separate thread |
*args:_P.args | positional arguments to be passed to func |
**kw:_P.kwargs | keyword arguments to be passed to func |
Increase the number of available workers for the thread pool by 1, up to the maximum allowed by ThreadPool.max
.
For legacy compatibility purposes, return the number of idle workers as expressed by a list the length of that number.
For legacy compatibility purposes, return the number of busy workers as expressed by a list the length of that number.