def worker():
while True:
item = q.get()
do_work(item)
q.task_done()
q = Queue()
for i in range(num_worker_threads):
t = Thread(target=worker)
t.daemon = True
t.start()
for item in source():
q.put(item)
q.join()
我不明白的是,source()函数是什么,“items”是什么?在
我有一个班是这样做的:
^{pr2}$
在我的GUI脚本中,我调用了类的do\u them\u all():some_button(command = get_it_done)
def get_it_done():
get_done = do_stuff()
get_done.do_them_all()
而每一个做事情的功能都是靠前一个功能来完成的。但在最后的类植入中,dousomething_3可能在dousomethingu2完成之前被触发,或者dousomethingu2在dousomethingu1完成之前被触发。在
如何实现这个队列?
我是否要修改do\u them\u all():def do_them_all():
queue.put(do_some_thing_1)
queue.put(do_some_thing_2)
queue.put(do_some_thing_3)
queue.join()