Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`python`.`threadpool`.`ThreadPool``

class documentation

`class ThreadPool: (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.

Method | `__getstate__` | Undocumented
Method | `__init__` | Create a new threadpool.
Method | `__setstate__` | Undocumented
Method | `adjustPoolsize` | Adjust the number of available threads by setting `min` and `max` to new values.
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 | `dumpStats` | Dump some plain-text informational messages to the log about the state of this `ThreadPool`.
Method | `start` | Start the threadpool.
Method | `startAWorker` | 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 | `stopAWorker` | Decrease the number of available workers by 1, by quitting one as soon as it's idle.
Class Variable | `currentThread` | 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 | `_generateName` | 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.

def __getstate__(self): (source)

Undocumented

def __init__(self, minthreads=5, maxthreads=20, name=None): (source)

Create a new threadpool.

Parameters
minthreads:`int` | minimum number of threads in the pool
maxthreads:`int` | maximum number of threads in the pool
name:native `str` | The name to give this threadpool; visible in log messages.

def __setstate__(self, state): (source)

Undocumented

def adjustPoolsize(self, minthreads=None, maxthreads=None): (source)

Adjust the number of available threads by setting `min` and `max` to new values.

Parameters
minthreads | The new value for `ThreadPool.min`.
maxthreads | The new value for `ThreadPool.max`.

def callInThread(self, func, *args, **kw): (source)

Call a callable object in a separate thread.

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`

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.

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, `onResult` may be `None`, in which case it is not called at all.
func | callable object to be called in separate thread
*args | positional arguments to be passed to `func`
**kw | keyword arguments to be passed to `func`

def dumpStats(self): (source)

Dump some plain-text informational messages to the log about the state of this `ThreadPool`.

def start(self): (source)

Start the threadpool.

def startAWorker(self): (source)

Increase the number of available workers for the thread pool by 1, up to the maximum allowed by `ThreadPool.max`.

def stop(self): (source)

Shutdown the threads in the threadpool.

def stopAWorker(self): (source)

Decrease the number of available workers by 1, by quitting one as soon as it's idle.

currentThread = (source)

Undocumented

joined: `bool` = (source)

Undocumented

max = (source)

Undocumented

min = (source)

Undocumented

name = (source)

Undocumented

started: `bool` = (source)

Whether or not the thread pool is currently running.

threads: `list` = (source)

List of workers currently running in this thread pool.

@property
waiters: `list` of `None` = (source)

For legacy compatibility purposes, return the number of idle workers as expressed by a list the length of that number.

@property
workers: `int` = (source)

For legacy compatibility purposes, return a total number of workers.

@property
working: `list` of `None` = (source)

For legacy compatibility purposes, return the number of busy workers as expressed by a list the length of that number.

def _generateName(self): (source)

Generate a name for a new pool thread.

Returns
native `str` | A distinctive name for the thread.

_pool: callable compatible with `_pool` = (source)

A hook for testing.

_team = (source)

Undocumented

@property
_queue = (source)

For legacy compatibility purposes, return an object with a `qsize` method that indicates the amount of work not yet allocated to a worker.