mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #6963: Added maxtasksperchild argument to multiprocessing.Pool
This commit is contained in:
parent
2deb5c758a
commit
654ade3e6a
6 changed files with 130 additions and 19 deletions
|
@ -45,7 +45,7 @@ latin = str
|
|||
#
|
||||
|
||||
LOG_LEVEL = util.SUBWARNING
|
||||
#LOG_LEVEL = logging.WARNING
|
||||
#LOG_LEVEL = logging.DEBUG
|
||||
|
||||
DELTA = 0.1
|
||||
CHECK_TIMINGS = False # making true makes tests take a lot longer
|
||||
|
@ -1052,6 +1052,30 @@ class _TestPool(BaseTestCase):
|
|||
join = TimingWrapper(self.pool.join)
|
||||
join()
|
||||
self.assertTrue(join.elapsed < 0.2)
|
||||
|
||||
class _TestPoolWorkerLifetime(BaseTestCase):
|
||||
|
||||
ALLOWED_TYPES = ('processes', )
|
||||
def test_pool_worker_lifetime(self):
|
||||
p = multiprocessing.Pool(3, maxtasksperchild=10)
|
||||
self.assertEqual(3, len(p._pool))
|
||||
origworkerpids = [w.pid for w in p._pool]
|
||||
# Run many tasks so each worker gets replaced (hopefully)
|
||||
results = []
|
||||
for i in range(100):
|
||||
results.append(p.apply_async(sqr, (i, )))
|
||||
# Fetch the results and verify we got the right answers,
|
||||
# also ensuring all the tasks have completed.
|
||||
for (j, res) in enumerate(results):
|
||||
self.assertEqual(res.get(), sqr(j))
|
||||
# Refill the pool
|
||||
p._repopulate_pool()
|
||||
# Finally, check that the worker pids have changed
|
||||
finalworkerpids = [w.pid for w in p._pool]
|
||||
self.assertNotEqual(sorted(origworkerpids), sorted(finalworkerpids))
|
||||
p.close()
|
||||
p.join()
|
||||
|
||||
#
|
||||
# Test that manager has expected number of shared objects left
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue