Skip to content

Commit

Permalink
Update _test_multiprocessing.py for python#116849
Browse files Browse the repository at this point in the history
ResourceTracker of a child process should not raise warnings or try to clean up SharedMemory if it was created and is still in use by the parent process. Even if ResourceTracker was asked to track that memory. 
If that was allowed, an error is raised when the parent process tries to unlink the memory later.

Previous commit also makes manual unregistration from resource_tracker unneeded.
  • Loading branch information
zetadin authored May 17, 2024
1 parent a8b7b7c commit 5ef59d5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,9 @@ def test_shared_memory_tracking(self):
# gh-82300: When a separate Python process accesses shared memory
# with track=True, it must cause the memory to be deleted when
# terminating.
# gh-116849: Tracking should only be applied when shared memory
# is created, otherwize an error is raised when it is unlinked
# in a different process.
cmd = '''if 1:
import sys
from multiprocessing.shared_memory import SharedMemory
Expand All @@ -4542,15 +4545,16 @@ def test_shared_memory_tracking(self):
try:
rc, out, err = script_helper.assert_python_ok("-c", cmd, mem.name)
self.assertEqual(rc, 0)
self.assertIn(
self.assertNotIn(
b"resource_tracker: There appear to be 1 leaked "
b"shared_memory objects to clean up at shutdown", err)
finally:
try:
mem.unlink()
except OSError:
pass
resource_tracker.unregister(mem._name, "shared_memory")
except OSError as e:
self.assertIn(
b"[Errno 2] No such file or directory", str(e)
)
mem.close()

#
Expand Down

0 comments on commit 5ef59d5

Please sign in to comment.