Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Lib/test/test_multiprocessing.py

Issue 10332: Multiprocessing maxtasksperchild results in hang
Patch Set: Created 8 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/multiprocessing/pool.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 # 3 #
4 # Unit tests for the multiprocessing package 4 # Unit tests for the multiprocessing package
5 # 5 #
6 6
7 import unittest 7 import unittest
8 import queue as pyqueue 8 import queue as pyqueue
9 import time 9 import time
10 import io 10 import io
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 countdown -= 1 1258 countdown -= 1
1259 time.sleep(DELTA) 1259 time.sleep(DELTA)
1260 finalworkerpids = [w.pid for w in p._pool] 1260 finalworkerpids = [w.pid for w in p._pool]
1261 # All pids should be assigned. See issue #7805. 1261 # All pids should be assigned. See issue #7805.
1262 self.assertNotIn(None, origworkerpids) 1262 self.assertNotIn(None, origworkerpids)
1263 self.assertNotIn(None, finalworkerpids) 1263 self.assertNotIn(None, finalworkerpids)
1264 # Finally, check that the worker pids have changed 1264 # Finally, check that the worker pids have changed
1265 self.assertNotEqual(sorted(origworkerpids), sorted(finalworkerpids)) 1265 self.assertNotEqual(sorted(origworkerpids), sorted(finalworkerpids))
1266 p.close() 1266 p.close()
1267 p.join() 1267 p.join()
1268
1269 def test_pool_worker_lifetime_early_close(self):
1270 # Issue #10332: closing a pool whose workers have limited lifetimes
1271 # before all the tasks completed would make join() hang.
1272 p = multiprocessing.Pool(3, maxtasksperchild=1)
1273 results = []
1274 for i in range(6):
1275 results.append(p.apply_async(sqr, (i, 0.3)))
1276 p.close()
1277 p.join()
1278 # check the results
1279 for (j, res) in enumerate(results):
1280 self.assertEqual(res.get(), sqr(j))
1281
1268 1282
1269 # 1283 #
1270 # Test that manager has expected number of shared objects left 1284 # Test that manager has expected number of shared objects left
1271 # 1285 #
1272 1286
1273 class _TestZZZNumberOfObjects(BaseTestCase): 1287 class _TestZZZNumberOfObjects(BaseTestCase):
1274 # Because test cases are sorted alphabetically, this one will get 1288 # Because test cases are sorted alphabetically, this one will get
1275 # run after all the other tests for the manager. It tests that 1289 # run after all the other tests for the manager. It tests that
1276 # there have been no "reference leaks" for the manager's shared 1290 # there have been no "reference leaks" for the manager's shared
1277 # objects. Note the comment in _TestPool.test_terminate(). 1291 # objects. Note the comment in _TestPool.test_terminate().
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 ManagerMixin.pool.terminate() 2378 ManagerMixin.pool.terminate()
2365 ManagerMixin.manager.shutdown() 2379 ManagerMixin.manager.shutdown()
2366 2380
2367 del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool 2381 del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
2368 2382
2369 def main(): 2383 def main():
2370 test_main(unittest.TextTestRunner(verbosity=2).run) 2384 test_main(unittest.TextTestRunner(verbosity=2).run)
2371 2385
2372 if __name__ == '__main__': 2386 if __name__ == '__main__':
2373 main() 2387 main()
OLDNEW
« no previous file with comments | « Lib/multiprocessing/pool.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+