Package twisted :: Package python :: Module threadpool :: Class ThreadPool

[frames | no frames]

## Class ThreadPool

This class (hopefully) generalizes the functionality of a pool of threads to which work can be dispatched.

dispatch(), dispatchWithCallback() and stop() should only be called from a single thread, unless you make a subclass where stop() and _startSomeWorkers() are synchronized.

Method Summary
| ``__init__`(self, minthreads, maxthreads)` Create a new threadpool.
| `__getstate__(self)`
| `__setstate__(self, state)`
| `_runWithCallback(self, callback, errback, func, args, kwargs)`
| `_startSomeWorkers(self)`
| `_worker(self, o)`
| `adjustPoolsize(self, minthreads, maxthreads)`
| `callInThread(self, func, *args, **kw)`
| ``dispatch`(self, owner, func, *args, **kw)` Dispatch a function to be a run in a thread.
| ``dispatchWithCallback`(self, owner, callback, errback, func, *args, **kw)` Dispatch a function, returning the result to a callback function.
| `dumpStats(self)`
| ``start`(self)` Start the threadpool.
| `startAWorker(self)`
| ``stop`(self)` Shutdown the threads in the threadpool.
| `stopAWorker(self)`

Class Variable Summary
`int` | `_ThreadPool__inited` = 0
`int` | `joined` = 0
`int` | `max` = 20
`int` | `min` = 5
`int` | `started` = 0
`int` | `workers` = 0

Method Details

### __init__(self, minthreads=5, maxthreads=20)
(Constructor)

Create a new threadpool.

  Parameters:
    `minthreads` - minimum number of threads in the pool
    `maxthreads` - maximum number of threads in the pool

### dispatch(self, owner, func, *args, **kw)

Dispatch a function to be a run in a thread.

### dispatchWithCallback(self, owner, callback, errback, func, *args, **kw)

Dispatch a function, returning the result to a callback function.

The callback function will be called in the thread - make sure it is thread-safe.

### start(self)

Start the threadpool.

### stop(self)

Shutdown the threads in the threadpool.

Class Variable Details

### _ThreadPool__inited

  Type:
    `int`
  Value:

        0

### joined

  Type:
    `int`
  Value:

        0

### max

  Type:
    `int`
  Value:

        20

### min

  Type:
    `int`
  Value:

        5

### started

  Type:
    `int`
  Value:

        0

### workers

  Type:
    `int`
  Value:

        0

Generated by Epydoc 2.0 on Sat May 15 20:07:44 2004 | http://epydoc.sf.net