Skip to content

Commit 19a6526

Browse files
committed
gh-96026: do not unregister without register in shm POSIX error handling
`multiprocessing.shared_memory.SharedMemory` currently tries to unlink a POSIX shared memory object if it fails to mmap it after opening/creating it in the constructor. It does this by calling `cleanup()`, which unregisters the shared memory despite it not having been registered. This will trigger a separate exception in the resource tracker. Fix this by calling the low-level unlink directly.
1 parent 6970bd3 commit 19a6526

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Lib/multiprocessing/shared_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__(self, name=None, create=False, size=0, *, track=True):
116116
size = stats.st_size
117117
self._mmap = mmap.mmap(self._fd, size)
118118
except:
119-
self.unlink()
119+
_posixshmem.shm_unlink(self._name)
120120
raise
121121
if self._track:
122122
resource_tracker.register(self._name, "shared_memory")

0 commit comments

Comments
 (0)