[3.13] gh-130730: Fix multiprocessing test_active_children() (GH-130837) (#130845)

gh-130730: Fix multiprocessing test_active_children() (GH-130837)

Replace a sleep with an event: sleep is not a reliable
synchronization primitive.
(cherry picked from commit 3dd3675492)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2025-03-04 18:28:33 +01:00 committed by GitHub
parent a115480f71
commit 22d729cf5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -588,12 +588,16 @@ class _TestProcess(BaseTestCase):
def test_active_children(self):
self.assertEqual(type(self.active_children()), list)
p = self.Process(target=time.sleep, args=(DELTA,))
event = self.Event()
p = self.Process(target=event.wait, args=())
self.assertNotIn(p, self.active_children())
p.daemon = True
p.start()
self.assertIn(p, self.active_children())
try:
p.daemon = True
p.start()
self.assertIn(p, self.active_children())
finally:
event.set()
p.join()
self.assertNotIn(p, self.active_children())