MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / StoppableWorker

Class StoppableWorker

example_code/item_070.py:251–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249
250print("Example 18")
251class StoppableWorker(Thread):
252 def __init__(self, func, in_queue, out_queue):
253 super().__init__()
254 self.func = func
255 self.in_queue = in_queue
256 self.out_queue = out_queue
257
258 def run(self):
259 while True:
260 try:
261 item = self.in_queue.get()
262 except ShutDown:
263 return
264 else:
265 result = self.func(item)
266 self.out_queue.put(result)
267 self.in_queue.task_done()
268
269
270print("Example 19")

Callers 2

item_070.pyFile · 0.70
start_threadsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected