diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2012-05-02 18:36:11 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2012-05-02 18:36:11 (GMT) |
commit | 225cb8d077b9d34ec20480aad3cbd9018798546f (patch) | |
tree | 9e55124874a98a163a27990f7e1d10a37339842f /Lib/test/test_multiprocessing.py | |
parent | d59240de8311a493ead948f382cc07e0d70fb1c1 (diff) | |
download | cpython-225cb8d077b9d34ec20480aad3cbd9018798546f.zip cpython-225cb8d077b9d34ec20480aad3cbd9018798546f.tar.gz cpython-225cb8d077b9d34ec20480aad3cbd9018798546f.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/test_multiprocessing.py')
-rw-r--r-- | 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 index c87b967..792db25 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2555,6 +2555,8 @@ def _afunc(x): 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 @@ def test_main(run=None): 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) |