Skip to content

Commit 8ba561c

Browse files
committed
gh-149879: Fix multiprocessing tests on Cygwin
* Disable fork and forkserver start methods on Cygwin * Disable AF_UNIX connection family on Cygwin
1 parent 14af19e commit 8ba561c

8 files changed

Lines changed: 20 additions & 15 deletions

File tree

Lib/multiprocessing/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
default_family = 'AF_INET'
5151
families = ['AF_INET']
5252

53-
if hasattr(socket, 'AF_UNIX'):
53+
if hasattr(socket, 'AF_UNIX') and sys.platform != 'cygwin':
5454
default_family = 'AF_UNIX'
5555
families += ['AF_UNIX']
5656

Lib/multiprocessing/context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,15 @@ def _check_available(self):
324324
raise ValueError('forkserver start method not available')
325325

326326
_concrete_contexts = {
327-
'fork': ForkContext(),
328327
'spawn': SpawnContext(),
329-
'forkserver': ForkServerContext(),
330328
}
329+
if sys.platform != 'cygwin':
330+
_concrete_contexts['fork'] = ForkContext()
331+
_concrete_contexts['forkserver'] = ForkServerContext()
331332
# bpo-33725: running arbitrary code after fork() is no longer reliable
332333
# on macOS since macOS 10.14 (Mojave). Use spawn by default instead.
333334
# gh-84559: We changed everyones default to a thread safeish one in 3.14.
334-
if reduction.HAVE_SEND_HANDLE and sys.platform != 'darwin':
335+
if reduction.HAVE_SEND_HANDLE and sys.platform not in ('darwin', 'cygwin'):
335336
_default_context = DefaultContext(_concrete_contexts['forkserver'])
336337
else:
337338
_default_context = DefaultContext(_concrete_contexts['spawn'])

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def _resource_unlink(name, rtype):
142142
'HAVE_BROKEN_SEM_GETVALUE', False)
143143

144144
WIN32 = (sys.platform == "win32")
145+
ALL_START_METHODS = multiprocessing.get_all_start_methods()
145146

146147
def wait_for_handle(handle, timeout):
147148
if timeout is not None and timeout < 0.0:
@@ -239,6 +240,8 @@ class TestInternalDecorators(unittest.TestCase):
239240
"""Logic within a test suite that could errantly skip tests? Test it!"""
240241

241242
@support.requires_fork()
243+
# Cygwin has fork() but lacks start method 'fork'
244+
@unittest.skipUnless('fork' in ALL_START_METHODS, 'need fork start method')
242245
def test_only_run_in_spawn_testsuite(self):
243246
if multiprocessing.get_start_method() != "spawn":
244247
raise unittest.SkipTest("only run in test_multiprocessing_spawn.")
@@ -6104,7 +6107,7 @@ def test_set_get(self):
61046107
def test_get_all_start_methods(self):
61056108
methods = multiprocessing.get_all_start_methods()
61066109
self.assertIn('spawn', methods)
6107-
if sys.platform == 'win32':
6110+
if sys.platform in ('win32', 'cygwin'):
61086111
self.assertEqual(methods, ['spawn'])
61096112
elif sys.platform == 'darwin':
61106113
self.assertEqual(methods[0], 'spawn') # The default is first.
@@ -6138,7 +6141,7 @@ def test_preload_resources(self):
61386141
self.fail("failed spawning forkserver or grandchild")
61396142

61406143
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
6141-
@unittest.skipIf(sys.platform == "win32",
6144+
@unittest.skipIf(sys.platform in ("win32", "cygwin"),
61426145
"Only Spawn on windows so no risk of mixing")
61436146
@only_run_in_spawn_testsuite("avoids redundant testing.")
61446147
def test_mixed_startmethod(self):

Lib/test/test_concurrent_futures/test_init.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def _assert_logged(self, msg):
120120
create_executor_tests(globals(), FailingInitializerMixin)
121121

122122

123-
@unittest.skipIf(sys.platform == "win32", "Resource Tracker doesn't run on Windows")
123+
@unittest.skipIf(sys.platform in ("win32", "cygwin"),
124+
"Resource Tracker doesn't run on Windows")
124125
class FailingInitializerResourcesTest(unittest.TestCase):
125126
"""
126127
Source: https://github.com/python/cpython/issues/104090

Lib/test/test_concurrent_futures/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def get_context(self):
101101
_check_system_limits()
102102
except NotImplementedError:
103103
self.skipTest("ProcessPoolExecutor unavailable on this system")
104-
if sys.platform == "win32":
105-
self.skipTest("require unix system")
104+
if sys.platform in ("win32", "cygwin"):
105+
self.skipTest("require Unix system")
106106
if support.check_sanitizer(thread=True):
107107
self.skipTest("TSAN doesn't support threads after fork")
108108
return super().get_context()
@@ -135,8 +135,8 @@ def get_context(self):
135135
_check_system_limits()
136136
except NotImplementedError:
137137
self.skipTest("ProcessPoolExecutor unavailable on this system")
138-
if sys.platform == "win32":
139-
self.skipTest("require unix system")
138+
if sys.platform in ("win32", "cygwin"):
139+
self.skipTest("require Unix system")
140140
if support.check_sanitizer(thread=True):
141141
self.skipTest("TSAN doesn't support threads after fork")
142142
return super().get_context()

Lib/test/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,7 +4066,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self):
40664066

40674067
import multiprocessing
40684068

4069-
if support.MS_WINDOWS:
4069+
if support.MS_WINDOWS or sys.platform == 'cygwin':
40704070
start_methods = ['spawn']
40714071
else:
40724072
start_methods = ['spawn', 'fork', 'forkserver']
@@ -4085,7 +4085,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self):
40854085
" assertions in multiprocessing")
40864086
def test_config_queue_handler_multiprocessing_context(self):
40874087
# regression test for gh-121723
4088-
if support.MS_WINDOWS:
4088+
if support.MS_WINDOWS or sys.platform == 'cygwin':
40894089
start_methods = ['spawn']
40904090
else:
40914091
start_methods = ['spawn', 'fork', 'forkserver']

Lib/test/test_multiprocessing_fork/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if support.PGO:
77
raise unittest.SkipTest("test is not helpful for PGO")
88

9-
if sys.platform == "win32":
9+
if sys.platform in ("win32", "cygwin"):
1010
raise unittest.SkipTest("fork is not available on Windows")
1111

1212
if sys.platform == 'darwin':

Lib/test/test_multiprocessing_forkserver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if support.PGO:
77
raise unittest.SkipTest("test is not helpful for PGO")
88

9-
if sys.platform == "win32":
9+
if sys.platform in ("win32", "cygwin"):
1010
raise unittest.SkipTest("forkserver is not available on Windows")
1111

1212
if not support.has_fork_support:

0 commit comments

Comments
 (0)