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.
This commit is contained in:
parent
d59240de83
commit
225cb8d077
@ -2555,6 +2555,8 @@ def _afunc(x):
|
|||||||
def pool_in_process():
|
def pool_in_process():
|
||||||
pool = multiprocessing.Pool(processes=4)
|
pool = multiprocessing.Pool(processes=4)
|
||||||
x = pool.map(_afunc, [1, 2, 3, 4, 5, 6, 7])
|
x = pool.map(_afunc, [1, 2, 3, 4, 5, 6, 7])
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
|
|
||||||
class _file_like(object):
|
class _file_like(object):
|
||||||
def __init__(self, delegate):
|
def __init__(self, delegate):
|
||||||
@ -2808,14 +2810,17 @@ def test_main(run=None):
|
|||||||
|
|
||||||
loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase
|
loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase
|
||||||
suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases)
|
suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases)
|
||||||
run(suite)
|
try:
|
||||||
|
run(suite)
|
||||||
ThreadsMixin.pool.terminate()
|
finally:
|
||||||
ProcessesMixin.pool.terminate()
|
ThreadsMixin.pool.terminate()
|
||||||
ManagerMixin.pool.terminate()
|
ProcessesMixin.pool.terminate()
|
||||||
ManagerMixin.manager.shutdown()
|
ManagerMixin.pool.terminate()
|
||||||
|
ManagerMixin.pool.join()
|
||||||
del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
|
ManagerMixin.manager.shutdown()
|
||||||
|
ThreadsMixin.pool.join()
|
||||||
|
ProcessesMixin.pool.join()
|
||||||
|
del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
test_main(unittest.TextTestRunner(verbosity=2).run)
|
test_main(unittest.TextTestRunner(verbosity=2).run)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user