t.p.t.ThreadPool : class documentation

Part of twisted.python.threadpool View Source View In Hierarchy

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, unless you make a subclass where stop and _startSomeWorkers are synchronized.

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 _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.
def __init__(self, minthreads=5, maxthreads=20, name=None): (source)
Create a new threadpool.
Parametersminthreadsminimum number of threads in the pool
maxthreadsmaximum number of threads in the pool
def start(self): (source)
Start the threadpool.
def startAWorker(self): (source)
Undocumented
def stopAWorker(self): (source)
Undocumented
def __setstate__(self, state): (source)
Undocumented
def __getstate__(self): (source)
Undocumented
def _startSomeWorkers(self): (source)
Undocumented
def callInThread(self, func, *args, **kw): (source)
Call a callable object in a separate thread.
Parametersfunccallable object to be called in separate thread
*argspositional arguments to be passed to func
**kwkeyword args to be passed to func
def callInThreadWithCallback(self, onResult, func, *args, **kw): (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.

ParametersonResulta 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 None, in which case it is not called at all.

funccallable object to be called in separate thread
*argspositional arguments to be passed to func
**kwargskeyword arguments to be passed to func
def _worker(self): (source)
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.
def stop(self): (source)
Shutdown the threads in the threadpool.
def adjustPoolsize(self, minthreads=None, maxthreads=None): (source)
Undocumented
def dumpStats(self): (source)
Undocumented
API Documentation for Twisted, generated by pydoctor at 2012-09-01 11:44:56.