python - python multiprocessing Queue 对于对象放置是否安全?

标签 python queue multiprocessing deep-copy

当我将对象放入 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.

关于python - python multiprocessing Queue 对于对象放置是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41673522/

相关文章:

python - 如何在 python/windows 下对 I/O 事务设置超时并取消它?

python - 从 Python 中没有今天日期的列表中获取所有值

java - Java模拟医院(优先队列)

java - Java中的并发和阻塞队列

laravel - 将 Laravel 事件订阅者排队

Python 多进程/线程循环。

python - Python 中具有多个参数的方法的多重处理

python - 调用 setup.py install 时编译翻译文件

python - 如何使用 Paramiko 运行 sudo? (Python)

python - Django - 使用 Celery 7 天后更新字段值