Using a a manager for updating a Queue in a Python multiprocess(在 Python 多进程中使用管理器更新队列)
问题描述
我正在设计一个 Python 多处理代码以在一个队列中工作,该队列可能会在处理过程中更新.下面的代码有时会起作用,或者卡住,或者出现 Empty 错误.
I am designing a Python multiprocessing code to work in a queue that might be updated along the processing. The following code sometimes works, or get stuck, or rises an Empty error.
我应该使用列表作为全局变量并锁定它,而不是 manager.Queue()?
Should I use a list as a global variable, and lock it, instead of a manager.Queue()?
推荐答案
我刚刚添加了一个 try:
和 except Exception:
来处理 Empty 错误.现在的结果似乎是一致的.如果您发现我在此解决方案中忽略的问题,请告诉我.
I just added a try:
and except Exception:
to handle the Empty error. The results seem to be consistent now. Please let me know If you find problems I overlooked in this solution.
这篇关于在 Python 多进程中使用管理器更新队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!