简体   繁体   English

Python多处理共享内存:列表列表

[英]Python multiprocessing shared memory: list of lists

Is it possible to share memory for a list of lists using multiprocessing.Array() or something similar? 是否可以使用multiprocessing.Array()或类似的东西共享内存列表? Also, is it possible to share a more complex object such as a scipy.sparse.lil_matrix ? 另外,是否可以共享更复杂的对象,例如scipy.sparse.lil_matrix How would I go about doing that? 我该怎么做呢? Are there any examples for either? 是否有任何例子? This variable doesn't have to be modified, but it consumes a lot of memory (~1GB per process), and I'm hoping shared memory will cut back the memory usage. 这个变量不需要修改,但是它消耗了大量内存(每个进程大约1GB),我希望共享内存会减少内存使用量。 Or is that incorrect? 或者这是不正确的?

In general, no (and Python is especially bad at copy-on-write multiprocessing, because even reading an object means changing its refcount, and that's a write operation). 通常,没有(并且Python在写入时复制多处理方面特别糟糕,因为即使读取对象也意味着更改其引用计数,这就是写入操作)。

You could, however, try to work with memory-mapped files. 但是,您可以尝试使用内存映射文件。 Dump your dataset in one, open it from multiple processes and reap the benefits of your OS's I/O caching. 将您的数据集转储为一个,从多个流程中打开它,并获得操作系统I / O缓存的好处。

What are you doing with your dataset? 你在用你的数据集做什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM