当我将对象放入 Queue 时, 是否需要创建对象的深拷贝然后放入队列?
最佳答案
如果能保证Object只在一个Thread中处理,这不是问题。但是如果不能,建议使用深拷贝。
如果您将对象放入 Queue 对象,它不会自动执行此操作。
查看引用
- Multithreading, Python and passed arguments
- Python in Practice: Create Better Programs Using Concurrency... p.154
请记住,对象需要能够被 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.
关于python - python multiprocessing Queue 对于对象放置是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41673522/