From 2c7afbcd823e0c1c30091dc17bd1363e41a7bc58 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Thu, 1 Dec 2022 09:51:48 -0800 Subject: [PATCH 1/2] chore: convert multiprocessing set_spawn to fixture in pytest --- tests/conftest.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 96dffc81cc..9b4f12b8e0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,15 +17,19 @@ # Early diagnostic for failed imports import pybind11_tests -if os.name != "nt": - # Full background: https://github.com/pybind/pybind11/issues/4105#issuecomment-1301004592 - # In a nutshell: fork() after starting threads == flakiness in the form of deadlocks. - # It is actually a well-known pitfall, unfortunately without guard rails. - # "forkserver" is more performant than "spawn" (~9s vs ~13s for tests/test_gil_scoped.py, - # visit the issuecomment link above for details). - # Windows does not have fork() and the associated pitfall, therefore it is best left - # running with defaults. - multiprocessing.set_start_method("forkserver") + +@pytest.fixture(scope="session", autouse=True) +def always_forkserver_on_unix(): + if os.name != "nt": + # Full background: https://github.com/pybind/pybind11/issues/4105#issuecomment-1301004592 + # In a nutshell: fork() after starting threads == flakiness in the form of deadlocks. + # It is actually a well-known pitfall, unfortunately without guard rails. + # "forkserver" is more performant than "spawn" (~9s vs ~13s for tests/test_gil_scoped.py, + # visit the issuecomment link above for details). + # Windows does not have fork() and the associated pitfall, therefore it is best left + # running with defaults. + multiprocessing.set_start_method("forkserver") + _long_marker = re.compile(r"([0-9])L") _hexadecimal = re.compile(r"0x[0-9a-fA-F]+") From 9b9d0402a33d96901c25463bf7902ce8c1494071 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Thu, 1 Dec 2022 11:46:41 -0800 Subject: [PATCH 2/2] Switch to early return --- tests/conftest.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9b4f12b8e0..402fd4b25b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,15 +20,17 @@ @pytest.fixture(scope="session", autouse=True) def always_forkserver_on_unix(): - if os.name != "nt": - # Full background: https://github.com/pybind/pybind11/issues/4105#issuecomment-1301004592 - # In a nutshell: fork() after starting threads == flakiness in the form of deadlocks. - # It is actually a well-known pitfall, unfortunately without guard rails. - # "forkserver" is more performant than "spawn" (~9s vs ~13s for tests/test_gil_scoped.py, - # visit the issuecomment link above for details). - # Windows does not have fork() and the associated pitfall, therefore it is best left - # running with defaults. - multiprocessing.set_start_method("forkserver") + if os.name == "nt": + return + + # Full background: https://github.com/pybind/pybind11/issues/4105#issuecomment-1301004592 + # In a nutshell: fork() after starting threads == flakiness in the form of deadlocks. + # It is actually a well-known pitfall, unfortunately without guard rails. + # "forkserver" is more performant than "spawn" (~9s vs ~13s for tests/test_gil_scoped.py, + # visit the issuecomment link above for details). + # Windows does not have fork() and the associated pitfall, therefore it is best left + # running with defaults. + multiprocessing.set_start_method("forkserver") _long_marker = re.compile(r"([0-9])L")