Can anybody help? Thanks in advance!
Sabine Lorentz
Code: Alles auswählen
from Queue import Queue
from threading import Thread
num_worker_threads = 2
def do_work(c):
a, b = 0, 1
while b < c:
#print b
a, b = b, a+b
print b
return b;
def worker():
while True:
item = q.get()
do_work(item)
q.task_done()
return;
q = Queue()
for i in range(num_worker_threads):
t = Thread(target=worker)
t.setDaemon(True)
t.start()
print "Start."
#q.put(10)
q.put(301)
q.put(25)
q.join(5) # block until all tasks are do
#o = do_work(25);
#print o
#o = do_work(301);
#print o
print "End."