From 3bc5cb7e0db13ba3885c8ed3d51ea792738499b2 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Thu, 4 Mar 2010 15:58:54 +0000 Subject: #7805: wait until all workers are started before collecting their PIDs --- Lib/multiprocessing/process.py | 2 +- Lib/test/test_multiprocessing.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py index 56719d9..998dab7 100644 --- a/Lib/multiprocessing/process.py +++ b/Lib/multiprocessing/process.py @@ -179,7 +179,7 @@ class Process(object): @property def ident(self): ''' - Return indentifier (PID) of process or `None` if it has yet to start + Return identifier (PID) of process or `None` if it has yet to start ''' if self is _current_process: return os.getpid() diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 24366a7..6e585c1 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1070,8 +1070,16 @@ class _TestPoolWorkerLifetime(BaseTestCase): self.assertEqual(res.get(), sqr(j)) # Refill the pool p._repopulate_pool() - # Finally, check that the worker pids have changed + # Wait until all workers are alive + countdown = 5 + while countdown and not all(w.is_alive() for w in p._pool): + countdown -= 1 + time.sleep(DELTA) finalworkerpids = [w.pid for w in p._pool] + # All pids should be assigned. See issue #7805. + self.assertNotIn(None, origworkerpids) + self.assertNotIn(None, finalworkerpids) + # Finally, check that the worker pids have changed self.assertNotEqual(sorted(origworkerpids), sorted(finalworkerpids)) p.close() p.join() -- cgit v0.12