Opened 3 years ago
Last modified 3 years ago
#64806 new defect
multiprocess.shared_memory.SharedMemory name too long
Reported by: | gma-uw (gma1) | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | |
Keywords: | Cc: | ||
Port: |
Description
From the python documentation example at https://docs.python.org/3/library/multiprocessing.shared_memory.html
from multiprocessing import shared_memory shm_a = shared_memory.SharedMemory(create=True, size=10, name='a'*31) type(shm_a.buf) buffer = shm_a.buf print (len(buffer)) buffer[:4] = bytearray([22, 33, 44, 55]) # Modify multiple at once buffer[4] = 100 # Modify single byte at a time # Attach to an existing shared memory block shm_b = shared_memory.SharedMemory(shm_a.name) import array array.array('b', shm_b.buf[:5]) # Copy the data into a new array.array shm_b.buf[:5] = b'howdy' # Modify via shm_b using bytes bytes(shm_a.buf[:5]) # Access via shm_a shm_b.close() # Close each SharedMemory instance shm_a.close() shm_a.unlink() # Call unlink only once to release the shared memory
If name is longer that 30 characters, I get the error: OSError: [Errno 63] File name too long: '/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
The documentation https://docs.python.org/3/library/multiprocessing.shared_memory.html says nothing about the length of name.
This is on an M1 Mac.
Note: See
TracTickets for help on using
tickets.
This appears to be an upstream documentation bug if anything. There's a reference in the code to 14 characters being the maximum safe name length at least on FreeBSD: https://github.com/python/cpython/blob/3.10/Lib/multiprocessing/shared_memory.py#L29
The underlying posix shared memory API has a name length limit of
PSHMNAMLEN
, defined insys/posix_shm.h
.