8000 bpo-37421: test_concurrent_futures cleans up multiprocessing (GH-14563) · python/cpython@684cb47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 684cb47

Browse files
authored
bpo-37421: test_concurrent_futures cleans up multiprocessing (GH-14563)
test_concurrent_futures now cleans up multiprocessing to remove immediately temporary directories created by multiprocessing.util.get_temp_dir(). The test now uses setUpModule() and tearDownModule().
1 parent b71d8d6 commit 684cb47

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

Lib/test/test_concurrent_futures.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
from concurrent.futures.process import BrokenProcessPool
2828
from multiprocessing import get_context
2929

30+
import multiprocessing.process
31+
import multiprocessing.util
32+
3033

3134
def create_future(state=PENDING, exception=None, result=None):
3235
f = Future()
@@ -1293,12 +1296,24 @@ def test_multiple_set_exception(self):
12931296
self.assertEqual(f.exception(), e)
12941297

12951298

1296-
@test.support.reap_threads
1297-
def test_main():
1298-
try:
1299-
test.support.run_unittest(__name__)
1300-
finally:
1301-
test.support.reap_children()
1299+
_threads_key = None
1300+
1301+
def setUpModule():
1302+
global _threads_key
1303+
_threads_key = test.support.threading_setup()
1304+
1305+
1306+
def tearDownModule():
1307+
test.support.threading_cleanup(*_threads_key)
1308+
test.support.reap_children()
1309+
1310+
# cleanup multiprocessing
1311+
multiprocessing.process._cleanup()
1312+
# bpo-37421: Explicitly call _run_finalizers() to remove immediately
1313+
# temporary directories created by multiprocessing.util.get_temp_dir().
1314+
multiprocessing.util._run_finalizers()
1315+
test.support.gc_collect()
1316+
13021317

13031318
if __name__ == "__main__":
1304-
test_main()
1319+
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test_concurrent_futures now cleans up multiprocessing to remove immediately
2+
temporary directories created by multiprocessing.util.get_temp_dir().

0 commit comments

Comments
 (0)
0