Skip to content

Commit 225cb8d

Browse files
committed
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.
1 parent d59240d commit 225cb8d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

‎Lib/test/test_multiprocessing.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,8 @@ def _afunc(x):
25552555
def pool_in_process():
25562556
pool = multiprocessing.Pool(processes=4)
25572557
x = pool.map(_afunc, [1, 2, 3, 4, 5, 6, 7])
2558+
pool.close()
2559+
pool.join()
25582560

25592561
class _file_like(object):
25602562
def __init__(self, delegate):
@@ -2808,14 +2810,17 @@ def test_main(run=None):
28082810

28092811
loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase
28102812
suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases)
2811-
run(suite)
2812-
2813-
ThreadsMixin.pool.terminate()
2814-
ProcessesMixin.pool.terminate()
2815-
ManagerMixin.pool.terminate()
2816-
ManagerMixin.manager.shutdown()
2817-
2818-
del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
2813+
try:
2814+
run(suite)
2815+
finally:
2816+
ThreadsMixin.pool.terminate()
2817+
ProcessesMixin.pool.terminate()
2818+
ManagerMixin.pool.terminate()
2819+
ManagerMixin.pool.join()
2820+
ManagerMixin.manager.shutdown()
2821+
ThreadsMixin.pool.join()
2822+
ProcessesMixin.pool.join()
2823+
del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
28192824

28202825
def main():
28212826
test_main(unittest.TextTestRunner(verbosity=2).run)

0 commit comments

Comments
 (0)