Python队列get()/task_done()问题 [英] Python Queue get()/task_done() issue
问题描述
我的消费方队列:
m = queue.get()
queue.task_done()
<rest of the program>
问题:
-
task_done()
是否有效地将m
从队列中弹出并释放消费者在队列上的所有锁定? -
在程序的其余部分中,我需要使用
m
.是安全的,还是我需要在调用task_done()
之前复制它,或者m
在task_done()
之后可用?
开心
否,queue.get()
将项目从队列中弹出.完成此操作后,只要生产者按其应有的方式工作并且不再碰它,就可以随心所欲地对其进行操作.调用queue.task_done()
仅是为了通知队列您已完成某件事(它甚至不知道特定项目,它只计算队列中未完成的项目),以便queue.join()
知道工作已完成. /p>
My consumer side of the queue:
m = queue.get()
queue.task_done()
<rest of the program>
Questions:
Does
task_done()
effectively popsm
off the queue and release whatever locks the consumer has on the queue?I need to use
m
during the rest of the program. Is it safe, or do I need to copy it before I calltask_done()
or ism
usable aftertask_done()
?
be happy
No, queue.get()
pops the item off the queue. After you do that, you can do whatever you want with it, as long as the producer works like it should and doesn't touch it anymore. queue.task_done()
is called only to notify the queue that you are done with something (it doesn't even know about the specific item, it just counts unfinished items in the queue), so that queue.join()
knows the work is finished.
这篇关于Python队列get()/task_done()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!