MCPcopy Create free account
hub / github.com/ActiveState/code / PoolWorker

Class PoolWorker

recipes/Python/576519_Thread_pool_same_API/recipe-576519.py:69–85  ·  view source on GitHub ↗

Thread that consumes WorkUnits from a queue to process them

Source from the content-addressed store, hash-verified

67
68
69class 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
88class Pool(object):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected