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() 问题


基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01