[Python-checkins] cpython: Make test_multiprocessing cleanup properly

richard.oudkerk python-checkins at python.org
Wed May 2 20:45:06 CEST 2012


http://hg.python.org/cpython/rev/e54adf13e7a6
changeset: 76716:e54adf13e7a6
user: Richard Oudkerk <shibturn at gmail.com>
date: Wed May 02 19:36:11 2012 +0100
summary:
 Make test_multiprocessing cleanup properly
Previously, when an error was encountered some processes would not be
stopped until atexit callbacks were run. On Windows that was too late
to prevent a PermissionError when regrtest tried to remove the temp
directory it ran the tests in.
files:
 Lib/test/test_multiprocessing.py | 21 ++++++++++++-------
 1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -2555,6 +2555,8 @@
 def pool_in_process():
 pool = multiprocessing.Pool(processes=4)
 x = pool.map(_afunc, [1, 2, 3, 4, 5, 6, 7])
+ pool.close()
+ pool.join()
 
 class _file_like(object):
 def __init__(self, delegate):
@@ -2808,14 +2810,17 @@
 
 loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase
 suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases)
- run(suite)
-
- ThreadsMixin.pool.terminate()
- ProcessesMixin.pool.terminate()
- ManagerMixin.pool.terminate()
- ManagerMixin.manager.shutdown()
-
- del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
+ try:
+ run(suite)
+ finally:
+ ThreadsMixin.pool.terminate()
+ ProcessesMixin.pool.terminate()
+ ManagerMixin.pool.terminate()
+ ManagerMixin.pool.join()
+ ManagerMixin.manager.shutdown()
+ ThreadsMixin.pool.join()
+ ProcessesMixin.pool.join()
+ del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
 
 def main():
 test_main(unittest.TextTestRunner(verbosity=2).run)
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /