-
-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest-xdist --forked can break on darwin #194290
Comments
Ah, splendid. I remember this issue from our python setup at work. The pytestXdistHook() {
pytestFlagsArray+=(
"--numprocesses=$NIX_BUILD_CORES"
"--forked"
)
}
[...] The question is whether we just allow unsafe forking for the pytest-xdist setup hook, or find a way to not pass |
We run pytest with `--forked` in nixpkgs, to reduce side effects that can occur when multiple tests mutate their environment in incompatible ways. Forking on macOS 10.13 and later is unsafe when an application does work between calls to fork() and its followup exec(). This may lead to crashes when calls into the Objective-C runtime are issued, which will in turn coredump the Python interpreter. One good reproducer for this scenario is when the urllib module tries to lookup proxy configurations in `urllib.request.getproxies()` through `get_proxies_macos_sysconf` into the native `_scproxy` module. This is a class of issues that is of course not limited to the urllib module. The general recommendation is to use `spawn` instead of `fork`, but we don't have any influence on upstream developers to do one or the other. One often cited workaround would be to disable fork safety entirely on calls to `initialize()`, which is probably a better solution than running without multithreading (slow) or without the `--forked` (prone to side effects) mode. This currently happens on aarch64-linux only, where we use more recent 11.0 SDK version, while x86_64-darwin has been stuck on 10.12 for a while now. python/cpython#77906 (comment) http://www.sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html Closes: NixOS#194290
Steps To Reproduce
Build log
Segmentation fault when running tests on Darwin (at least, on aarch64-darwin):
with stack trace:
Additional context
From OSX 10.12+, functions that access ObjC libraries cannot be called after forking. In this case, the poetry tests are running into https://bugs.python.org/issue30385#msg293958. This was enough of a problem that Python 3.8 switched to using "spawn" instead of "fork" when using the multiprocess library (python/cpython#77906), but this doesn't impact pytest-forked since it explicitly calls
os.fork
.Suggestion: don't use "--forked" (at least on Darwin)
Notify maintainers
@Artturin @dotlambda @mweinelt
The text was updated successfully, but these errors were encountered: