Python Queue get()/task_done() issue(Python 队列 get()/task_done() 问题)
问题描述
我的消费者端:
m = queue.get()
queue.task_done()
<rest of the program>
问题:
task_done()
是否有效地将m
从队列中弹出并释放消费者在队列中的所有锁?
Does
task_done()
effectively popsm
off 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() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 队列 get()/task_done() 问题


- 我如何卸载 PyTorch? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01