Skip to content

Commit 9eb50a4

Browse files
authored
gh-149879: Fix multiprocessing tests on Cygwin (#150031)
* Disable AF_UNIX connection family on Cygwin. * forkserver start method is not available on Cygwin: update tests for that. * test_logging calls multiprocessing.get_all_start_methods().
1 parent 0aa59ce commit 9eb50a4

5 files changed

Lines changed: 13 additions & 14 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ def _check_available(self):
326326
_concrete_contexts = {
327327
'fork': ForkContext(),
328328
'spawn': SpawnContext(),
329-
'forkserver': ForkServerContext(),
330329
}
330+
if reduction.HAVE_SEND_HANDLE:
331+
_concrete_contexts['forkserver'] = ForkServerContext()
332+
331333
# bpo-33725: running arbitrary code after fork() is no longer reliable
332334
# on macOS since macOS 10.14 (Mojave). Use spawn by default instead.
333335
# gh-84559: We changed everyones default to a thread safeish one in 3.14.

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6143,7 +6143,10 @@ def test_preload_resources(self):
61436143
@only_run_in_spawn_testsuite("avoids redundant testing.")
61446144
def test_mixed_startmethod(self):
61456145
# Fork-based locks cannot be used with spawned process
6146-
for process_method in ["spawn", "forkserver"]:
6146+
test_methods = ["spawn"]
6147+
if "forkserver" in multiprocessing.get_all_start_methods():
6148+
test_methods.append("forkserver")
6149+
for process_method in test_methods:
61476150
queue = multiprocessing.get_context("fork").Queue()
61486151
process_ctx = multiprocessing.get_context(process_method)
61496152
p = process_ctx.Process(target=close_queue, args=(queue,))
@@ -6152,7 +6155,7 @@ def test_mixed_startmethod(self):
61526155
p.start()
61536156

61546157
# non-fork-based locks can be used with all other start methods
6155-
for queue_method in ["spawn", "forkserver"]:
6158+
for queue_method in test_methods:
61566159
for process_method in multiprocessing.get_all_start_methods():
61576160
queue = multiprocessing.get_context(queue_method).Queue()
61586161
process_ctx = multiprocessing.get_context(process_method)

Lib/test/test_logging.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,11 +4065,7 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self):
40654065
# and thus cannot be used as a queue-like object (gh-124653)
40664066

40674067
import multiprocessing
4068-
4069-
if support.MS_WINDOWS:
4070-
start_methods = ['spawn']
4071-
else:
4072-
start_methods = ['spawn', 'fork', 'forkserver']
4068+
start_methods = multiprocessing.get_all_start_methods()
40734069

40744070
for start_method in start_methods:
40754071
with self.subTest(start_method=start_method):
@@ -4085,10 +4081,8 @@ def test_config_reject_simple_queue_handler_multiprocessing_context(self):
40854081
" assertions in multiprocessing")
40864082
def test_config_queue_handler_multiprocessing_context(self):
40874083
# regression test for gh-121723
4088-
if support.MS_WINDOWS:
4089-
start_methods = ['spawn']
4090-
else:
4091-
start_methods = ['spawn', 'fork', 'forkserver']
4084+
import multiprocessing
4085+
start_methods = multiprocessing.get_all_start_methods()
40924086
for start_method in start_methods:
40934087
with self.subTest(start_method=start_method):
40944088
ctx = multiprocessing.get_context(start_method)

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)