Make test_tokamak_parameter spawn-safe#560
Open
samc24 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Sameer Chaturvedi <sameerc@mit.edu>
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
Fix
tests/test_decorator.py::test_tokamak_parameter[None]hanging indefinitely under multiprocessing'sspawnstart method (macOS default; Linux default in Python 3.14+).Root cause
The test defined
my_physics_methodas a function-localglobal. Underfork(current Linux default), spawned workers inherit the parent process's module globals, so the attribute exists. Underspawn/forkserver, workersre-import the test module from scratch —
my_physics_methoddoesn't exist yet because the test function hasn't run there — so unpickling the function reference fails:AttributeError: Can't get attribute 'my_physics_method' on <module 'test_decorator'>
The worker dies silently; the parent pool waits forever on
queue.get().Fix
Move the two physics-method variants to module scope and parametrize over the method rather than the tokamak argument. Module-scope functions exist at import time, so spawned workers can find them by reference.
No production code changes.
Why this matters now
Python 3.14 makes
forkserverthe default POSIX start method. The current pattern works on Linux CI today only because it forks; that breaks when the project moves to 3.14. This fix preempts the Linux-CI failure as well as fixing theexisting macOS hang, and unblocks the macOS test matrix being introduced on
glt/macbook.Behavior change
Test IDs change:
test_tokamak_parameter[None]→test_tokamak_parameter[tokamak=None]test_tokamak_parameter[Tokamak.<X>]→test_tokamak_parameter[tokamak=resolved]Test plan
pytest tests/test_decorator.py::test_tokamak_parameter— both parametrizations pass in ~16s on macOS (spawn default)make black/ ruff / pylint clean on changed file