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 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() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 队列 get()/task_done() 问题
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
