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

Class ThreadPool

recipes/Python/577187_Python_Thread_Pool/recipe-577187.py:19–31  ·  view source on GitHub ↗

Pool of threads consuming tasks from a queue

Source from the content-addressed store, hash-verified

17 self.tasks.task_done()
18
19class ThreadPool:
20 """Pool of threads consuming tasks from a queue"""
21 def __init__(self, num_threads):
22 self.tasks = Queue(num_threads)
23 for _ in range(num_threads): Worker(self.tasks)
24
25 def add_task(self, func, *args, **kargs):
26 """Add a task to the queue"""
27 self.tasks.put((func, args, kargs))
28
29 def wait_completion(self):
30 """Wait for completion of all the tasks in the queue"""
31 self.tasks.join()
32
33if __name__ == '__main__':
34 from random import randrange

Callers 1

recipe-577187.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected