]> granicus.if.org Git - python/commitdiff
bpo-37421: test_concurrent_futures cleans up multiprocessing (GH-14563)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 3 Jul 2019 09:36:13 +0000 (02:36 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2019 09:36:13 +0000 (02:36 -0700)
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().
(cherry picked from commit 684cb47fffb7af3ac50cb077f6d2a095c9ce20b4)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Lib/test/test_concurrent_futures.py
Misc/NEWS.d/next/Tests/2019-07-02-23-29-06.bpo-37421.WEfc5A.rst [new file with mode: 0644]

index b27ae719482285ba9d7d84293afd0acba46f3db3..fa298207f6c509de23aef1c622ee3145cf86adcf 100644 (file)
@@ -27,6 +27,9 @@ from concurrent.futures._base import (
 from concurrent.futures.process import BrokenProcessPool
 from multiprocessing import get_context
 
+import multiprocessing.process
+import multiprocessing.util
+
 
 def create_future(state=PENDING, exception=None, result=None):
     f = Future()
@@ -1294,12 +1297,24 @@ class FutureTests(BaseTestCase):
         self.assertEqual(f.exception(), e)
 
 
-@test.support.reap_threads
-def test_main():
-    try:
-        test.support.run_unittest(__name__)
-    finally:
-        test.support.reap_children()
+_threads_key = None
+
+def setUpModule():
+    global _threads_key
+    _threads_key = test.support.threading_setup()
+
+
+def tearDownModule():
+    test.support.threading_cleanup(*_threads_key)
+    test.support.reap_children()
+
+    # cleanup multiprocessing
+    multiprocessing.process._cleanup()
+    # bpo-37421: Explicitly call _run_finalizers() to remove immediately
+    # temporary directories created by multiprocessing.util.get_temp_dir().
+    multiprocessing.util._run_finalizers()
+    test.support.gc_collect()
+
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()
diff --git a/Misc/NEWS.d/next/Tests/2019-07-02-23-29-06.bpo-37421.WEfc5A.rst b/Misc/NEWS.d/next/Tests/2019-07-02-23-29-06.bpo-37421.WEfc5A.rst
new file mode 100644 (file)
index 0000000..215a0a1
--- /dev/null
@@ -0,0 +1,2 @@
+test_concurrent_futures now cleans up multiprocessing to remove immediately
+temporary directories created by multiprocessing.util.get_temp_dir().