using thread pool
[arrocco.git] / spawn / pool.py
blobe9761d37056e4d6c470065f7e68ff9d0c80ec124
1 # pool.py
2 # 11 Sep 2007
4 import Queue, thread
5 q = Queue.Queue()
6 inited = False
8 def initialize():
9 global inited; inited = True
10 for i in range(50):
11 thread.start_new_thread(persistent_worker, ())
13 def persistent_worker():
14 while True:
15 computation = q.get()
16 computation()
18 def start_new_thread(f, args, kwargs = None):
19 if not inited: initialize()
20 if not kwargs: kwargs = {}
21 q.put(lambda: f(*args, **kwargs))