https://github.com/python/cpython/commit/4827968af87d828554c3fadd97094c97798541b4
commit: 4827968af87d828554c3fadd97094c97798541b4
branch: main
author: Malcolm Smith <[email protected]>
committer: gpshead <[email protected]>
date: 2024-02-25T11:38:18-08:00
summary:

gh-71052: Enable test_concurrent_futures on platforms that lack multiprocessing 
(gh-115917)

Enable test_concurrent_futures on platforms that support threading but not 
multiprocessing.

files:
A Misc/NEWS.d/next/Tests/2024-02-25-15-58-28.gh-issue-71052.lxBjqY.rst
M Lib/multiprocessing/queues.py
M Lib/test/test___all__.py
M Lib/test/test_concurrent_futures/__init__.py
M Lib/test/test_concurrent_futures/test_init.py
M Lib/test/test_concurrent_futures/util.py

diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index 852ae87b276861..925f043900004e 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -20,8 +20,6 @@
 
 from queue import Empty, Full
 
-import _multiprocessing
-
 from . import connection
 from . import context
 _ForkingPickler = context.reduction.ForkingPickler
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index c87cde4b3d1fab..19dcbb207e914a 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -5,11 +5,6 @@
 import sys
 import types
 
-try:
-    import _multiprocessing
-except ModuleNotFoundError:
-    _multiprocessing = None
-
 
 if support.check_sanitizer(address=True, memory=True):
     SKIP_MODULES = frozenset((
@@ -36,17 +31,6 @@ class FailedImport(RuntimeError):
 
 class AllTest(unittest.TestCase):
 
-    def setUp(self):
-        # concurrent.futures uses a __getattr__ hook. Its __all__ triggers
-        # import of a submodule, which fails when _multiprocessing is not
-        # available.
-        if _multiprocessing is None:
-            sys.modules["_multiprocessing"] = 
types.ModuleType("_multiprocessing")
-
-    def tearDown(self):
-        if _multiprocessing is None:
-            sys.modules.pop("_multiprocessing")
-
     def check_all(self, modname):
         names = {}
         with warnings_helper.check_warnings(
diff --git a/Lib/test/test_concurrent_futures/__init__.py 
b/Lib/test/test_concurrent_futures/__init__.py
index 430fa93aa456a2..17a2853173ba18 100644
--- a/Lib/test/test_concurrent_futures/__init__.py
+++ b/Lib/test/test_concurrent_futures/__init__.py
@@ -3,8 +3,6 @@
 from test import support
 from test.support import import_helper
 
-# Skip tests if _multiprocessing wasn't built.
-import_helper.import_module('_multiprocessing')
 
 if support.check_sanitizer(address=True, memory=True):
     # gh-90791: Skip the test because it is too slow when Python is built
diff --git a/Lib/test/test_concurrent_futures/test_init.py 
b/Lib/test/test_concurrent_futures/test_init.py
index d79a6367701fb4..113a4d1c54be03 100644
--- a/Lib/test/test_concurrent_futures/test_init.py
+++ b/Lib/test/test_concurrent_futures/test_init.py
@@ -5,6 +5,8 @@
 import unittest
 import sys
 from concurrent.futures._base import BrokenExecutor
+from concurrent.futures.process import _check_system_limits
+
 from logging.handlers import QueueHandler
 
 from test import support
@@ -117,6 +119,11 @@ class FailingInitializerResourcesTest(unittest.TestCase):
     """
 
     def _test(self, test_class):
+        try:
+            _check_system_limits()
+        except NotImplementedError:
+            self.skipTest("ProcessPoolExecutor unavailable on this system")
+
         runner = unittest.TextTestRunner()
         runner.run(test_class('test_initializer'))
 
diff --git a/Lib/test/test_concurrent_futures/util.py 
b/Lib/test/test_concurrent_futures/util.py
index dc48bec796b87f..3e855031913042 100644
--- a/Lib/test/test_concurrent_futures/util.py
+++ b/Lib/test/test_concurrent_futures/util.py
@@ -136,6 +136,12 @@ def strip_mixin(name):
 
 
 def setup_module():
-    unittest.addModuleCleanup(multiprocessing.util._cleanup_tests)
+    try:
+        _check_system_limits()
+    except NotImplementedError:
+        pass
+    else:
+        unittest.addModuleCleanup(multiprocessing.util._cleanup_tests)
+
     thread_info = threading_helper.threading_setup()
     unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info)
diff --git 
a/Misc/NEWS.d/next/Tests/2024-02-25-15-58-28.gh-issue-71052.lxBjqY.rst 
b/Misc/NEWS.d/next/Tests/2024-02-25-15-58-28.gh-issue-71052.lxBjqY.rst
new file mode 100644
index 00000000000000..8bac68b5aea78e
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2024-02-25-15-58-28.gh-issue-71052.lxBjqY.rst
@@ -0,0 +1,2 @@
+Enable ``test_concurrent_futures`` on platforms that support threading but not
+multiprocessing.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to