chore: Convert direct multiprocessing.set_start_method("forkserver") call to a pytest fixture. (#4377)

* chore: convert multiprocessing set_spawn to fixture in pytest

* Switch to early return
This commit is contained in:
Aaron Gokaslan 2022-12-01 15:15:47 -05:00 committed by GitHub
parent 358ba459d2
commit e133c33d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,12 @@ import pytest
# Early diagnostic for failed imports
import pybind11_tests
if os.name != "nt":
@pytest.fixture(scope="session", autouse=True)
def always_forkserver_on_unix():
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.
@ -27,6 +32,7 @@ if os.name != "nt":
# 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]+")