summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorsamtygier <samtygier@yahoo.co.uk>2022-06-16 13:41:51 (GMT)
committerGitHub <noreply@github.com>2022-06-16 13:41:51 (GMT)
commit9a458befdd68625d088f4fea7df135a57d147deb (patch)
treeb31d13db745f5d486d75cf112e9e2a554e47fbaf /Lib/multiprocessing
parenta38c2a61d585fce0973e93dd590551ccddd947fb (diff)
downloadcpython-9a458befdd68625d088f4fea7df135a57d147deb.zip
cpython-9a458befdd68625d088f4fea7df135a57d147deb.tar.gz
cpython-9a458befdd68625d088f4fea7df135a57d147deb.tar.bz2
gh-91577: SharedMemory move imports out of methods (#91579)
SharedMemory.unlink() uses the unregister() function from resource_tracker. Previously it was imported in the method, but this can fail if the method is called during interpreter shutdown, for example when unlink is part of a __del__() method. Moving the import to the top of the file, means that the unregister() method is available during interpreter shutdown. The register call in SharedMemory.__init__() can also use this imported resource_tracker.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/shared_memory.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/multiprocessing/shared_memory.py b/Lib/multiprocessing/shared_memory.py
index 122b3fc..881f200 100644
--- a/Lib/multiprocessing/shared_memory.py
+++ b/Lib/multiprocessing/shared_memory.py
@@ -23,6 +23,7 @@ else:
import _posixshmem
_USE_POSIX = True
+from . import resource_tracker
_O_CREX = os.O_CREAT | os.O_EXCL
@@ -116,8 +117,7 @@ class SharedMemory:
self.unlink()
raise
- from .resource_tracker import register
- register(self._name, "shared_memory")
+ resource_tracker.register(self._name, "shared_memory")
else:
@@ -237,9 +237,8 @@ class SharedMemory:
called once (and only once) across all processes which have access
to the shared memory block."""
if _USE_POSIX and self._name:
- from .resource_tracker import unregister
_posixshmem.shm_unlink(self._name)
- unregister(self._name, "shared_memory")
+ resource_tracker.unregister(self._name, "shared_memory")
_encoding = "utf8"