]> granicus.if.org Git - python/commitdiff
#7805: wait until all workers are started before collecting their PIDs
authorFlorent Xicluna <florent.xicluna@gmail.com>
Thu, 4 Mar 2010 15:58:54 +0000 (15:58 +0000)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Thu, 4 Mar 2010 15:58:54 +0000 (15:58 +0000)
Lib/multiprocessing/process.py
Lib/test/test_multiprocessing.py

index 56719d9c9cde17e11030405fdaaaf55d091f1841..998dab7c4bcdf03a0a81f10d0ec888b0a7a4f695 100644 (file)
@@ -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()
index 24366a70698b02dcf470cfbf127c7f471f6ec88b..6e585c110d0b34d4c6f4b7d61eb331ccbec9b3f9 100644 (file)
@@ -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()