0
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의 닫습니다 알 수있다 기본적인 예를 검토하세요?
만약'None'이 유효한 데이터라면'END_OF_DATA = object()'를 사용하여 데이터가 실제 센티넬 값인 경우에만'data is END_OF_DATA'가 참임을 보장해야합니다. – Bakuriu
Queue, Queue.get() 블록에 남아있는 항목이 없으면'data = q_in.get()'데이터는 None이 될 수 없습니다. – nacholibre
@nacholibre 제작자 (queue_add, worker)가 None을 넣기 때문에 q_in.get()은 None이 될 수 있습니다. – falsetru