diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index e37ec07d722ca8..be2fc3edf5dce6 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -50,7 +50,7 @@ default_family = 'AF_INET' families = ['AF_INET'] -if hasattr(socket, 'AF_UNIX'): +if hasattr(socket, 'AF_UNIX') and sys.platform != 'cygwin': default_family = 'AF_UNIX' families += ['AF_UNIX'] diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py index e1d251456024c0..0e7cbfdac94c0f 100644 --- a/Lib/multiprocessing/context.py +++ b/Lib/multiprocessing/context.py @@ -324,14 +324,15 @@ def _check_available(self): raise ValueError('forkserver start method not available') _concrete_contexts = { - 'fork': ForkContext(), 'spawn': SpawnContext(), - 'forkserver': ForkServerContext(), } + if sys.platform != 'cygwin': + _concrete_contexts['fork'] = ForkContext() + _concrete_contexts['forkserver'] = ForkServerContext() # bpo-33725: running arbitrary code after fork() is no longer reliable # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. # gh-84559: We changed everyones default to a thread safeish one in 3.14. - if reduction.HAVE_SEND_HANDLE and sys.platform != 'darwin': + if reduction.HAVE_SEND_HANDLE and sys.platform not in ('darwin', 'cygwin'): _default_context = DefaultContext(_concrete_contexts['forkserver']) else: _default_context = DefaultContext(_concrete_contexts['spawn']) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 580d9f2b32544e..24f54c2e76739a 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -142,6 +142,7 @@ def _resource_unlink(name, rtype): 'HAVE_BROKEN_SEM_GETVALUE', False) WIN32 = (sys.platform == "win32") +ALL_START_METHODS = multiprocessing.get_all_start_methods() def wait_for_handle(handle, timeout): if timeout is not None and timeout < 0.0: @@ -239,6 +240,8 @@ class TestInternalDecorators(unittest.TestCase): """Logic within a test suite that could errantly skip tests? Test it!""" @support.requires_fork() + # Cygwin has fork() but lacks start method 'fork' + @unittest.skipUnless('fork' in ALL_START_METHODS, 'need fork start method') def test_only_run_in_spawn_testsuite(self): if multiprocessing.get_start_method() != "spawn": raise unittest.SkipTest("only run in test_multiprocessing_spawn.") @@ -6104,7 +6107,7 @@ def test_set_get(self): def test_get_all_start_methods(self): methods = multiprocessing.get_all_start_methods() self.assertIn('spawn', methods) - if sys.platform == 'win32': + if sys.platform in ('win32', 'cygwin'): self.assertEqual(methods, ['spawn']) elif sys.platform == 'darwin': self.assertEqual(methods[0], 'spawn') # The default is first. @@ -6138,7 +6141,7 @@ def test_preload_resources(self): self.fail("failed spawning forkserver or grandchild") @warnings_helper.ignore_fork_in_thread_deprecation_warnings() - @unittest.skipIf(sys.platform == "win32", + @unittest.skipIf(sys.platform in ("win32", "cygwin"), "Only Spawn on windows so no risk of mixing") @only_run_in_spawn_testsuite("avoids redundant testing.") def test_mixed_startmethod(self): diff --git a/Lib/test/test_concurrent_futures/test_init.py b/Lib/test/test_concurrent_futures/test_init.py index 5ea543bf748982..65e04c0724d5ab 100644 --- a/Lib/test/test_concurrent_futures/test_init.py +++ b/Lib/test/test_concurrent_futures/test_init.py @@ -5,6 +5,7 @@ import unittest import sys import io +import multiprocessing from concurrent.futures._base import BrokenExecutor from concurrent.futures.process import _check_system_limits @@ -147,6 +148,9 @@ def test_spawn(self): self._test(ProcessPoolSpawnFailingInitializerTest) @support.skip_if_sanitizer("TSAN doesn't support threads after fork", thread=True) + # Cygwin doesn't have forkserver start method + @unittest.skipIf('forkserver' not in multiprocessing.get_all_start_methods(), + 'need forkserver start method') def test_forkserver(self): self._test(ProcessPoolForkserverFailingInitializerTest) diff --git a/Lib/test/test_concurrent_futures/util.py b/Lib/test/test_concurrent_futures/util.py index 2a9e55152b82d5..51e40a96516765 100644 --- a/Lib/test/test_concurrent_futures/util.py +++ b/Lib/test/test_concurrent_futures/util.py @@ -101,8 +101,8 @@ def get_context(self): _check_system_limits() except NotImplementedError: self.skipTest("ProcessPoolExecutor unavailable on this system") - if sys.platform == "win32": - self.skipTest("require unix system") + if sys.platform in ("win32", "cygwin"): + self.skipTest("require Unix system") if support.check_sanitizer(thread=True): self.skipTest("TSAN doesn't support threads after fork") return super().get_context() @@ -135,8 +135,8 @@ def get_context(self): _check_system_limits() except NotImplementedError: self.skipTest("ProcessPoolExecutor unavailable on this system") - if sys.platform == "win32": - self.skipTest("require unix system") + if sys.platform in ("win32", "cygwin"): + self.skipTest("require Unix system") if support.check_sanitizer(thread=True): self.skipTest("TSAN doesn't support threads after fork") return super().get_context() diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index f2cbc2514fce53..56e0fe7c531be7 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -4066,7 +4066,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self): import multiprocessing - if support.MS_WINDOWS: + if support.MS_WINDOWS or sys.platform == 'cygwin': start_methods = ['spawn'] else: start_methods = ['spawn', 'fork', 'forkserver'] @@ -4085,7 +4085,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self): " assertions in multiprocessing") def test_config_queue_handler_multiprocessing_context(self): # regression test for gh-121723 - if support.MS_WINDOWS: + if support.MS_WINDOWS or sys.platform == 'cygwin': start_methods = ['spawn'] else: start_methods = ['spawn', 'fork', 'forkserver'] diff --git a/Lib/test/test_multiprocessing_fork/__init__.py b/Lib/test/test_multiprocessing_fork/__init__.py index b35e82879d7fe2..cfa6d35dafef83 100644 --- a/Lib/test/test_multiprocessing_fork/__init__.py +++ b/Lib/test/test_multiprocessing_fork/__init__.py @@ -6,7 +6,7 @@ if support.PGO: raise unittest.SkipTest("test is not helpful for PGO") -if sys.platform == "win32": +if sys.platform in ("win32", "cygwin"): raise unittest.SkipTest("fork is not available on Windows") if sys.platform == 'darwin': diff --git a/Lib/test/test_multiprocessing_forkserver/__init__.py b/Lib/test/test_multiprocessing_forkserver/__init__.py index 7b1b884ab297b5..c58375e2861c62 100644 --- a/Lib/test/test_multiprocessing_forkserver/__init__.py +++ b/Lib/test/test_multiprocessing_forkserver/__init__.py @@ -6,7 +6,7 @@ if support.PGO: raise unittest.SkipTest("test is not helpful for PGO") -if sys.platform == "win32": +if sys.platform in ("win32", "cygwin"): raise unittest.SkipTest("forkserver is not available on Windows") if not support.has_fork_support: