提问人:Sharjil Bin Yousaf 提问时间:11/13/2023 更新时间:11/13/2023 访问量:17
无法访问从 1 个脚本创建的共享内存中的数据到其他脚本
Unable to access data in shared memory created from 1 script to other script
问:
我有两个脚本,一个脚本在共享内存中创建一个空间并在该共享内存中添加数据,另一个脚本正在访问该内存中的数据。但是我收到错误FileNotFoundError: [Errno 2] No such file or directory: '/psm_db77e072'
script1.py
from multiprocessing import shared_memory
shm_a = shared_memory.SharedMemory(name='psm_db77e072', create=True, size=10)
print(shm_a.name)
buffer = shm_a.buf
buffer[:4] = bytearray([22, 33, 44, 55]) # Modify multiple at once
buffer[4] = 100
script2.py
from multiprocessing import shared_memory
import array
shm_name = 'psm_db77e072' # Replace with the actual name from the first script
shm_b = shared_memory.SharedMemory(name=shm_name)
data_array = array.array('b', shm_b.buf[:5])
print(data_array)
答: 暂无答案
评论