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

Replace a sleep with an event: sleep is not a reliable
synchronization primitive.
This commit is contained in:
Victor Stinner 2025-03-04 18:05:20 +01:00 committed by GitHub
parent 885c3d126f
commit 3dd3675492
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -589,12 +589,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())