Package turbomail :: Module pool :: Class Pool
[hide private]
[frames] | no frames]

Class Pool

source code

        object --+        
                 |        
threading._Verbose --+    
                     |    
      threading.Thread --+
                         |
                        Pool
Known Subclasses:
MailPool

A threadpool which checks regularily for new jobs and spawns processes as needed.

Do not use this class directly. Always subclass and override the worker method.

Instance Methods [hide private]
 
__init__(self, interval=10, threads=4, jobs=10, timeout=60, polling=False, **kw)
Initialize the threadpool.
source code
 
enqueue(self, work, block=True, timeout=None)
Enqueue a Message instance.
source code
 
shutdown(self)
Quit the management thread and shutdown the queue.
source code
 
spawn(self) source code
 
run(self)
The management thread.
source code
 
wrapper(self)
Thread wrapper to log and keep track of the active thread count.
source code
 
worker(self)
This method must be overridden in a subclass and is used to perform the work of the threadpool.
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, interval=10, threads=4, jobs=10, timeout=60, polling=False, **kw)
(Constructor)

source code 
Initialize the threadpool.
Parameters:
  • interval (int) - A delay, in seconds, between spawn runs.
  • threads (int) - The maximum number of concurrent threads.
  • jobs (int) - The maximum number of jobs a single thread is allowed to handle before dying of old age.
  • timeout (int) - The amount of time, in seconds, a thread is allowed to sit idle before dying of starvation.
  • polling (bool) - Enable or disable the periodic polling mechanism. Disabled, threads will be created, as required, when work is enqueued.
Overrides: threading.Thread.__init__

enqueue(self, work, block=True, timeout=None)

source code 
Enqueue a Message instance.
Parameters:
  • work (callable) - The unit of work can be any callable that returns a three-item tuple containing the sender and recipient addresses and a properly formatted MIME message, in that order. The preferred type is an instance of the Message class or subclass.
  • block (bool) - Block code execution until there is a free slot in the queue. If block is True and timeout is None, block indefinately.
  • timeout (int) - How long to block execution (in seconds). If the timeout expires (or block is false and the queue is full) raise the Full exception.

run(self)

source code 

The management thread.

Do not call directly. Instead, use the start method.
Overrides: threading.Thread.run

worker(self)

source code 

This method must be overridden in a subclass and is used to perform the work of the threadpool.

Will raise a NotImplementedError exception if not subclassed.