问题描述
我的消费者端:
m = queue.get()
queue.task_done()
<rest of the program>
问题:
task_done()是否有效地将m从队列中弹出并释放消费者在队列中的所有锁?
Does
task_done()effectively popsmoff the queue and release whatever locks the consumer has on the queue?
我需要在程序的其余部分使用 m.它是否安全,或者我需要在调用 task_done() 之前复制它还是 m 在 task_done() 之后可用?
I need to use m during the rest of the program. Is it safe, or do I need to copy it before I call task_done() or is m usable after task_done()?
快乐
推荐答案
不,queue.get() 将项目从队列中弹出.在你这样做之后,你可以对它做任何你想做的事情,只要制作者按照它应该的方式工作并且不再触摸它.queue.task_done() 被调用只是为了通知队列你已经完成了某事(它甚至不知道具体的项目,它只是计算队列中未完成的项目),所以 queue.join() 知道工作已经完成.
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() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)