Python fork():将数据从子级传递到父级
我有一个主要的Python进程,以及由主进程使用 < 创建的一堆或多个工作进程代码>os.fork()。
我需要将大型且相当复杂的数据结构从工作人员传递回主流程。您会推荐哪些现有的库?
数据结构是列表、字典、 numpy 的混合
数组、自定义类(我可以调整)以及上述的多层组合。
应避免磁盘 I/O。如果我还可以避免创建数据副本(例如通过某种共享内存解决方案),那也很好,但不是硬性约束。
出于此问题的目的,必须使用 os.fork() 或其包装器来创建工作线程,以克隆主进程的地址空间。
这只需要在 Linux 上工作。
I have a main Python process, and a bunch or workers created by the main process using os.fork()
.
I need to pass large and fairly involved data structures from the workers back to the main process. What existing libraries would you recommend for that?
The data structures are a mix of lists, dictionaries, numpy
arrays, custom classes (which I can tweak) and multi-layer combinations of the above.
Disk I/O should be avoided. If I could also avoid creating copies of the data -- for example by having some kind of shared-memory solution -- that would be nice too, but is not a hard constraint.
For the purposes of this question, it is mandatory that the workers are created using os.fork()
, or a wrapper thereof that would clone the master process's address space.
This only needs to work on Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
multiprocessing
的队列实现有效。在内部,它将数据腌制到管道中。multiprocessing
's queue implementation works. Internally, it pickles data to a pipe.