Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a458be

Browse files
authored
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.
1 parenta38c2a6 commit9a458be

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎Lib/multiprocessing/shared_memory.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import_posixshmem
2424
_USE_POSIX=True
2525

26+
from .importresource_tracker
2627

2728
_O_CREX=os.O_CREAT|os.O_EXCL
2829

@@ -116,8 +117,7 @@ def __init__(self, name=None, create=False, size=0):
116117
self.unlink()
117118
raise
118119

119-
from .resource_trackerimportregister
120-
register(self._name,"shared_memory")
120+
resource_tracker.register(self._name,"shared_memory")
121121

122122
else:
123123

@@ -237,9 +237,8 @@ def unlink(self):
237237
called once (and only once) across all processes which have access
238238
to the shared memory block."""
239239
if_USE_POSIXandself._name:
240-
from .resource_trackerimportunregister
241240
_posixshmem.shm_unlink(self._name)
242-
unregister(self._name,"shared_memory")
241+
resource_tracker.unregister(self._name,"shared_memory")
243242

244243

245244
_encoding="utf8"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move imports in:class:`~multiprocessing.SharedMemory` methods to module level so that they can be executed late in python finalization.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp