1 '''A multithreaded implementation of the papyros master-slave API.'''
2
3 __all__ = ['MultiThreadedMaster', 'MultiThreadedSlave']
4
5 import logging
6 import threading
7 from papyros import Master, Slave
8
9 log = logging.getLogger('papyros')
10
11
13
14 - def __init__(self, num_slaves, poll_time=1, request_qsize=0, response_qsize=0):
15 '''Initialize this master and start C{num_slaves} slaves.
16
17 @param num_slaves: The number of slaves to start initially.
18 @param request_qsize: If a positive integer, it's the maximum number
19 of unassigned jobs. Trying to L{add <addJob>} a new L{Job}
20 when the queue is full blocks or raises C{Queue.Full} exception.
21 @param response_qsize: If a positive integer, it's the maximum number
22 of completed jobs waiting to be fetched. No more jobs are assigned
23 to the slaves when this number is reached.
24 '''
25 Master.__init__(self, request_qsize, response_qsize)
26 for _ in xrange(num_slaves):
27 MultiThreadedSlave(self, poll_time).start()
28 log.debug('Added %d slave threads' % num_slaves)
29
30
32 '''A L{Slave} implemented as a daemon thread.'''
33
34 - def __init__(self, master, poll_time=1):
38