Repository navigation
Conversation
`fork_context()` (added in e6279c5) returned `multiprocessing.get_context()` on macOS/Windows. Calling `get_context()` with no argument permanently fixes the interpreter's default start method, and `fork_context()` runs at import time via `class Process(fork_context().Process)`. Any code that imports autofit and then calls `multiprocessing.set_start_method(...)` therefore raised `RuntimeError: context has already been set`. The autofit test suite does exactly this on macOS in `test_autofit/conftest.py`, so `pytest` has failed to load the conftest on macOS since that commit. Return the `multiprocessing` module on those platforms instead. It exposes the same `Process` / `Queue` / `Pool` API but resolves the start method when a process is created, which is the pre-3.14 behaviour this helper exists to preserve. Non-macOS POSIX behaviour (pinned "fork") is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
3 tasks done
This was referenced Oct 7, 2026
samlange04
pushed a commit
to samlange04/PyAutoFit
that referenced
this pull request
Oct 7, 2026
…t import) Monkeypatch sys.platform to darwin/win32 and assert fork_context() returns the multiprocessing module (Process/Queue/Pool) and never calls multiprocessing.get_context() with no argument, the import-time call that fixed the default start method before PyAutoLabs#1657. Closes PyAutoLabs#1661 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Discussion: https://github.com/orgs/PyAutoLabs/discussions/27
Since e6279c5,
fork_context()inautofit/non_linear/parallel/context.pyreturnsmultiprocessing.get_context()(no argument) on macOS and Windows. That call permanently fixes the interpreter's default start method, andfork_context()runs at import time viaclass Process(fork_context().Process)inprocess.py. Any code that imports autofit and then callsmultiprocessing.set_start_method(...)raisesRuntimeError: context has already been set.test_autofit/conftest.pydoes exactly this on macOS, so plainpython -m pytest test_autofithas been unable to load the conftest on a Mac since 2026-07-31.This PR returns the
multiprocessingmodule on those platforms instead. It exposes the sameProcess/Queue/PoolAPI but resolves the start method when a process is created, which is the pre-3.14 behaviour the helper exists to preserve. Non-macOS POSIX behaviour (pinned"fork", the point of e6279c5) is unchanged. The docstring explains the reasoning.API Changes
fork_context()is internal. Its return type on macOS/Windows changes from aBaseContextinstance to themultiprocessingmodule, which supports every attribute autofit uses on it (Process,Queue,Pool). No downstream library callsfork_context().Test Plan
multiprocessing.context._default_context.get_contextto print a stack on the first call while the context was unset: fires fromparallel/process.py:47 -> parallel/context.py:33duringimport autofit.python -m pytest test_autofitfails withImportError while loading conftest ... RuntimeError: context has already been set. After: the conftest loads.python -m pytest test_autofit, 2924 passed, 39 skipped, 1 failed. The failure istest_autofit/non_linear/samples/test_pdf.py::test_save_covariance_matrix, a last-digit floating-point text comparison that fails identically on unmodifiedmain.test_autofit/non_linear/search/nest/): 38 passed, 13 skipped.sys.platform != "darwin"branch is untouched, so behaviour there should be identical. Needs CI to confirm.🤖 Generated with Claude Code