Allow ignoring SHM close failures
Useful if we export the mmap beyond the lifetime of the shm object
This commit is contained in:
parent
79f7954048
commit
dec62b1929
@ -49,9 +49,11 @@ class SharedMemory:
|
||||
def __init__(
|
||||
self, name: str = '', size: int = 0, readonly: bool = False,
|
||||
mode: int = stat.S_IREAD | stat.S_IWRITE,
|
||||
prefix: str = 'kitty-', unlink_on_exit: bool = False
|
||||
prefix: str = 'kitty-',
|
||||
unlink_on_exit: bool = False, ignore_close_failure: bool = False
|
||||
):
|
||||
self.unlink_on_exit = unlink_on_exit
|
||||
self.ignore_close_failure = ignore_close_failure
|
||||
if size < 0:
|
||||
raise TypeError("'size' must be a non-negative integer")
|
||||
if size and name:
|
||||
@ -157,7 +159,11 @@ class SharedMemory:
|
||||
"""Closes access to the shared memory from this instance but does
|
||||
not destroy the shared memory block."""
|
||||
if self._mmap is not None:
|
||||
try:
|
||||
self._mmap.close()
|
||||
except BufferError:
|
||||
if not self.ignore_close_failure:
|
||||
raise
|
||||
self._mmap = None
|
||||
if self._fd >= 0:
|
||||
os.close(self._fd)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user