Changeset 10

Show
Ignore:
Timestamp:
05/25/07 03:07:53 (2 years ago)
Author:
amcgregor
Message:

Merge patch from #5, with documentation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/turbomail/pool.py

    r1 r10  
    6060                log.debug("Thread pool created.") 
    6161         
    62         def enqueue(self, work): 
     62        def enqueue(self, work, block=True, timeout=None): 
    6363                """Enqueue a Message instance. 
    6464                 
     
    6969                             instance of the Message class or subclass. 
    7070                @type work: callable 
     71                 
     72                @param block: Block code execution until there is a free slot in 
     73                              the queue.  If I{block} is True and I{timeout} is 
     74                              None, block indefinately. 
     75                @type block: bool 
     76                 
     77                @param timeout: How long to block execution (in seconds).  If 
     78                                the timeout expires (or block is false and the 
     79                                queue is full) raise the Full exception. 
     80                @type timeout: int 
    7181                """ 
    7282 
    7383                if callable(work): 
    74                         self._queue.put(work()) 
     84                        self._queue.put(work(), block=block, timeout=timeout) 
    7585                else: 
    76                         self._queue.put(work) 
     86                        self._queue.put(work, block=block, timeout=timeout) 
    7787                 
    7888                optimum_threads = min(self._threads, math.ceil(self._queue.qsize() / float(self._jobs)))