Python Forum
multiprocessing.shared_memory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiprocessing.shared_memory
#1
I can create many instances of multiprocessing shared_memory.
But I can only access the last one that was created by name. Am I doing something wrong?, or is that the limit? Or do I first have to do something else if I want to access the others by name?

I am using Python 3.8.3 rc1 running on window10 version 1903.

def create_memory_names():


    names = []
    for i in range(2):
        a = np.zeros(shape=(FRAMESIZE), dtype=np.uint16)
        shm = multiprocessing.shared_memory.SharedMemory(create=True, size=a.nbytes)
        b = np.ndarray(a.shape, dtype=a.dtype, buffer=shm.buf)
        b[:] = a[:]
        logging.info(f"creatd name={shm.name}, shape={a.shape}, dtype={a.dtype}")
        names.append(shm.name)

    for i in reversed(names):
        shm = multiprocessing.shared_memory.SharedMemory(name = i)
        b = np.ndarray(a.shape, dtype=a.dtype, buffer=shm.buf)
        logging.info(f"accessed {i} by name")


create_memory_names()
---------
results in:
__________

INFO:root:creatd name=wnsm_0e727904, shape=(40,), dtype=uint16
INFO:root:creatd name=wnsm_f4f7cd3a, shape=(40,), dtype=uint16
INFO:root:accessed wnsm_f4f7cd3a by name
Traceback (most recent call last):
File "study_sharedmem.py", line 39, in <module>
create_memory_names()
File "study_sharedmem.py", line 34, in create_memory_names
shm = multiprocessing.shared_memory.SharedMemory(name = i)
File "shared_memory.py", line 158, in __init__
h_map = _winapi.OpenFileMapping(
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'wnsm_0e727904'
Reply
#2
Please use proper error tags while posting a thread.
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
sorry. So the error should have been:

Error:
INFO:root:creatd name=wnsm_0e727904, shape=(40,), dtype=uint16 INFO:root:creatd name=wnsm_f4f7cd3a, shape=(40,), dtype=uint16 INFO:root:accessed wnsm_f4f7cd3a by name Traceback (most recent call last): File "study_sharedmem.py", line 39, in <module> create_memory_names() File "study_sharedmem.py", line 34, in create_memory_names shm = multiprocessing.shared_memory.SharedMemory(name = i) File "shared_memory.py", line 158, in __init__ h_map = _winapi.OpenFileMapping( FileNotFoundError: [WinError 2] The system cannot find the file specified: 'wnsm_0e727904'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  multiprocessing doesnt contain some modules(shared_memory) mike000 3 871 Oct-31-2019, 02:20 PM
Last Post: mike000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020