简体   繁体   English

使用列表数组的共享内存的Python多处理

[英]Python multiprocessing for shared memory with an array of lists

I need to know if there is a way to share memory for an array of bool lists: 我需要知道是否有一种共享布尔列表数组的内存的方法:

s = Array( 'x' , range(10000000)) 

What do I have to write instead of x to make it an array of lists whose size is 64. Then I have to manipulate "s" in two different processes like these: 我要写什么而不是x来使其成为一个数组列表,数组的大小为64。那么我必须在两个不同的过程中操纵“ s”,如下所示:

#First

for i in range(0,photoCount):
    db.newDBS.insert_one({ 'photo' : s[i], 'user_id' : ids[i] })

#Second

s[photoCount].append = inPhoto

What should be the type? 应该是什么类型? Any help or suggestion appreciated. 任何帮助或建议表示赞赏。 Thank you! 谢谢!

Python Multiprocessing module allows 2 types of shared variables : Array , which is a simple 1D array of a single dtype, and Value , which is just a single value. Python Multiprocessing模块允许两种类型的共享变量: Array (它是单个dtype的简单一维数组)和Value ,它只是一个单一值。

You can design your own shared variables using ctype, if you know your way in C : see the documentation here. 如果您知道使用C的方式,则可以使用ctype设计自己的共享变量:请参见此处文档。

If you just need a 2D Array and you don't want to use ctype shared objects, maybe you could flatten your array in a single list and use multiprocessing.Array instead? 如果只需要2D数组,而又不想使用ctype共享对象,也许可以将数组展平在一个列表中,而改用multiprocessing.Array Then just reshape when your processing is done. 然后在处理完成后重塑形状。

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

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