この基本的な例を確認してください
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 を閉じる方法を知る方法ですか?