Thread that consumes WorkUnits from a queue to process them
| 67 | |
| 68 | |
| 69 | class PoolWorker(threading.Thread): |
| 70 | """Thread that consumes WorkUnits from a queue to process them""" |
| 71 | def __init__(self, workq, *args, **kwds): |
| 72 | """\param workq: Queue object to consume the work units from""" |
| 73 | threading.Thread.__init__(self, *args, **kwds) |
| 74 | self._workq = workq |
| 75 | |
| 76 | def run(self): |
| 77 | """Process the work unit, or wait for sentinel to exit""" |
| 78 | while 1: |
| 79 | workunit = self._workq.get() |
| 80 | if is_sentinel(workunit): |
| 81 | # Got sentinel |
| 82 | break |
| 83 | |
| 84 | # Run the job / sequence |
| 85 | workunit.process() |
| 86 | |
| 87 | |
| 88 | class Pool(object): |