mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
#7805: wait until all workers are started before collecting their PIDs
This commit is contained in:
parent
a36e245deb
commit
3bc5cb7e0d
2 changed files with 10 additions and 2 deletions
|
@ -179,7 +179,7 @@ class Process(object):
|
||||||
@property
|
@property
|
||||||
def ident(self):
|
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:
|
if self is _current_process:
|
||||||
return os.getpid()
|
return os.getpid()
|
||||||
|
|
|
@ -1070,8 +1070,16 @@ class _TestPoolWorkerLifetime(BaseTestCase):
|
||||||
self.assertEqual(res.get(), sqr(j))
|
self.assertEqual(res.get(), sqr(j))
|
||||||
# Refill the pool
|
# Refill the pool
|
||||||
p._repopulate_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]
|
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))
|
self.assertNotEqual(sorted(origworkerpids), sorted(finalworkerpids))
|
||||||
p.close()
|
p.close()
|
||||||
p.join()
|
p.join()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue