python 多处理队列对于对象放置是否安全?

Is python multiprocessing Queue safe for object put?

当我在Queue中放入对象时,是否需要创建对象的深拷贝然后放入队列?

如果能保证Object只在一个Thread中处理,这不是问题。但是如果不能,建议使用深拷贝。

如果您将对象放入 Queue 对象,它不会自动执行此操作。

查看参考资料

请记住,对象需要能够被 pickle (Multiprocessing Basics)

It usually more useful to be able to spawn a process with arguments to tell it what work to do. Unlike with threading, to pass arguments to a multiprocessing Process the argument must be able to be serialized using pickle. This example passes each worker a number so the output is a little more interesting.