Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Lib/multiprocessing/shared_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(self, name=None, create=False, size=0, *, track=True):

def __del__(self):
try:
self.close()
self._closefd()
except OSError:
pass

Expand Down Expand Up @@ -222,6 +222,11 @@ def size(self):
"Size in bytes."
return self._size

def _closefd(self):
if _USE_POSIX and self._fd >= 0:
os.close(self._fd)
self._fd = -1

def close(self):
"""Closes access to the shared memory from this instance but does
not destroy the shared memory block."""
Expand All @@ -231,9 +236,7 @@ def close(self):
if self._mmap is not None:
self._mmap.close()
self._mmap = None
if _USE_POSIX and self._fd >= 0:
os.close(self._fd)
self._fd = -1
self._closefd()

def unlink(self):
"""Requests that the underlying shared memory block be destroyed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an error in the finalizer of :class:`multiprocessing.shared_memory.SharedMemory`
which could leak a file descriptor.
Loading