Skip to content

Commit 1bf0a83

Browse files
appliovinay0410
authored andcommitted
Add test verifying shared memory available to other processes with handle after any one independent process exit.
1 parent dbdab82 commit 1bf0a83

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,27 @@ def test_shared_memory_across_processes(self):
39083908

39093909
sms.close()
39103910

3911+
def test_shared_memory_across_independently_started_processes(self):
3912+
# A Process may not trigger the same exit path as an independently
3913+
# spawned process (for example, resource trackers on a separate
3914+
# process). This tests that independently created processes can
3915+
# indeed continue to access shared memory and that that shared
3916+
# memory persists at least so long as one of the processes with a
3917+
# handle on it is alive.
3918+
sms = shared_memory.SharedMemory('test04_indep', True, size=256)
3919+
self.addCleanup(sms.unlink)
3920+
3921+
prog = (
3922+
"from multiprocessing import shared_memory; "
3923+
"sms = shared_memory.SharedMemory('test04_indep'); "
3924+
"sms.buf[:4] = b'1234'; "
3925+
"sms.close()"
3926+
)
3927+
rc, out, err = test.support.script_helper.assert_python_ok('-c', prog)
3928+
3929+
self.assertFalse(err)
3930+
self.assertEqual(bytes(sms.buf[:4]), b'1234')
3931+
39113932
@unittest.skipIf(os.name != "posix", "not feasible in non-posix platforms")
39123933
def test_shared_memory_SharedMemoryServer_ignores_sigint(self):
39133934
# bpo-36368: protect SharedMemoryManager server process from
@@ -3932,27 +3953,6 @@ def test_shared_memory_SharedMemoryServer_ignores_sigint(self):
39323953

39333954
smm.shutdown()
39343955

3935-
@unittest.skipIf(os.name != "posix", "resource_tracker is posix only")
3936-
def test_shared_memory_SharedMemoryManager_reuses_resource_tracker(self):
3937-
# bpo-36867: test that a SharedMemoryManager uses the
3938-
# same resource_tracker process as its parent.
3939-
cmd = '''if 1:
3940-
from multiprocessing.managers import SharedMemoryManager
3941-
3942-
3943-
smm = SharedMemoryManager()
3944-
smm.start()
3945-
sl = smm.ShareableList(range(10))
3946-
smm.shutdown()
3947-
'''
3948-
rc, out, err = test.support.script_helper.assert_python_ok('-c', cmd)
3949-
3950-
# Before bpo-36867 was fixed, a SharedMemoryManager not using the same
3951-
# resource_tracker process as its parent would make the parent's
3952-
# tracker complain about sl being leaked even though smm.shutdown()
3953-
# properly released sl.
3954-
self.assertFalse(err)
3955-
39563956
def test_shared_memory_SharedMemoryManager_basics(self):
39573957
smm1 = multiprocessing.managers.SharedMemoryManager()
39583958
with self.assertRaises(ValueError):
@@ -5075,9 +5075,6 @@ def create_and_register_resource(rtype):
50755075
if rtype == "semaphore":
50765076
lock = mp.Lock()
50775077
return lock, lock._semlock.name
5078-
elif rtype == "shared_memory":
5079-
sm = SharedMemory(create=True, size=10)
5080-
return sm, sm._name
50815078
else:
50825079
raise ValueError(
50835080
"Resource type {{}} not understood".format(rtype))

0 commit comments

Comments
 (0)