请查看此基本示例
def queue_add():
#this will exit when all lines from the
#file are added in the Queue
with open('get_from.txt') as f:
for line in f:
q.add(line.strip())
def queue_save():
#when to trigger save_to.close()?!?!
save_to = open('save_to.txt')
while True:
data = q.get() #this functions blocks if `q` is empty, so how to know
#when to close the file handler `save_to`??
save_to.write(data)
def worker():
#this is daemon process
while True:
#work with file from
get = q.get()
#work with data
q_done.put('processed data')
q.task_done()
q = Queue()
q_done = Queue()
#starts the processes here..
所以我的问题是如何知道queue_save()
已经处理并保存了 done_q 中的所有数据并关闭它的 file_handler?