From a1b3694499faf7be89f7b8ef9755f90e1aa469d9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 18 May 2026 23:52:27 +0200 Subject: [PATCH 1/2] gh-149879: Fix multiprocessing tests on Cygwin * Disable AF_UNIX connection family on Cygwin. * forkserver start method is not available on Cygwin: update tests for that. --- Lib/multiprocessing/connection.py | 2 +- Lib/multiprocessing/context.py | 4 +++- Lib/test/_test_multiprocessing.py | 7 +++++-- Lib/test/test_multiprocessing_forkserver/__init__.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) 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..45c393798deaca 100644 --- a/Lib/multiprocessing/context.py +++ b/Lib/multiprocessing/context.py @@ -326,8 +326,10 @@ def _check_available(self): _concrete_contexts = { 'fork': ForkContext(), 'spawn': SpawnContext(), - 'forkserver': ForkServerContext(), } + if reduction.HAVE_SEND_HANDLE: + _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. diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 580d9f2b32544e..f044358dcbd40f 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -6143,7 +6143,10 @@ def test_preload_resources(self): @only_run_in_spawn_testsuite("avoids redundant testing.") def test_mixed_startmethod(self): # Fork-based locks cannot be used with spawned process - for process_method in ["spawn", "forkserver"]: + test_methods = ["spawn"] + if "forkserver" in multiprocessing.get_all_start_methods(): + test_methods.append("forkserver") + for process_method in test_methods: queue = multiprocessing.get_context("fork").Queue() process_ctx = multiprocessing.get_context(process_method) p = process_ctx.Process(target=close_queue, args=(queue,)) @@ -6152,7 +6155,7 @@ def test_mixed_startmethod(self): p.start() # non-fork-based locks can be used with all other start methods - for queue_method in ["spawn", "forkserver"]: + for queue_method in test_methods: for process_method in multiprocessing.get_all_start_methods(): queue = multiprocessing.get_context(queue_method).Queue() process_ctx = multiprocessing.get_context(process_method) 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: From 9a53e4e6e4c4a33fd8b632f36611cebdfd3c4c19 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 May 2026 00:12:14 +0200 Subject: [PATCH 2/2] Fix test_logging --- Lib/test/test_logging.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index f2cbc2514fce53..2ab9e0b336c9fb 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -4065,11 +4065,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self): # and thus cannot be used as a queue-like object (gh-124653) import multiprocessing - - if support.MS_WINDOWS: - start_methods = ['spawn'] - else: - start_methods = ['spawn', 'fork', 'forkserver'] + start_methods = multiprocessing.get_all_start_methods() for start_method in start_methods: with self.subTest(start_method=start_method): @@ -4085,10 +4081,8 @@ 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: - start_methods = ['spawn'] - else: - start_methods = ['spawn', 'fork', 'forkserver'] + import multiprocessing + start_methods = multiprocessing.get_all_start_methods() for start_method in start_methods: with self.subTest(start_method=start_method): ctx = multiprocessing.get_context(start_method)