diff options
author | Jesse Noller <jnoller@gmail.com> | 2010-01-27 03:36:01 (GMT) |
---|---|---|
committer | Jesse Noller <jnoller@gmail.com> | 2010-01-27 03:36:01 (GMT) |
commit | 1f0b6586387a3dae59cf28239effe14f1333229a (patch) | |
tree | 5113af47512d196c433d6bcb695985bcbc21a14f /Lib/test/test_multiprocessing.py | |
parent | c3511a461de4e7370415b7de85eb193b6ee1548a (diff) | |
download | cpython-1f0b6586387a3dae59cf28239effe14f1333229a.zip cpython-1f0b6586387a3dae59cf28239effe14f1333229a.tar.gz cpython-1f0b6586387a3dae59cf28239effe14f1333229a.tar.bz2 |
Merged revisions 77794 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77794 | jesse.noller | 2010-01-26 22:05:57 -0500 (Tue, 26 Jan 2010) | 1 line
Issue #6963: Added maxtasksperchild argument to multiprocessing.Pool
........
Diffstat (limited to 'Lib/test/test_multiprocessing.py')
-rw-r--r-- | Lib/test/test_multiprocessing.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index b65fbf7..be923bd 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -46,7 +46,7 @@ def latin(s): # 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 @@ -1053,6 +1053,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 # |