multiprocessing.Array Segmentation fault

不打扰是莪最后的温柔 提交于 2019-12-12 05:06:05

问题


from multiprocessing import Value
from multiprocessing.sharedctypes import RawArray
from ctypes import addressof, c_char

array = RawArray(c_char, b'shirt')
array_length = array._length_
result_address = Value('i', 0)
result_address.value = addressof(array)
print((array._type_*array_length).from_address(result_address.value).value)

In one process I pass result_address of type multiprocessing.Value to a child process, which then creates an array in shared memory and writes its address back to result_address. Basically I want to share a bytestring created in child process with the parent process without using multiprocessing.Manager as it's only a bytestring and it can (?) be managed in shared memory.

Also this (array._type_*array_length).from_address() maybe creates the array in memory again, how do I just read the c array in python string without creating another array?

The code even does not work in single process and produces Segmentation fault.

来源:https://stackoverflow.com/questions/39702804/multiprocessing-array-segmentation-fault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!