fix(cpp): degrade gracefully when progress Manager cannot spawn (#339)#348
Draft
breimanntools wants to merge 1 commit into
Draft
fix(cpp): degrade gracefully when progress Manager cannot spawn (#339)#348breimanntools wants to merge 1 commit into
breimanntools wants to merge 1 commit into
Conversation
CPP.run(..., n_jobs>1) crashed in non-interactive contexts (python -c, heredocs, some subprocess shells) where multiprocessing.Manager() raised EOFError/OSError while setting up the cross-process progress bar. The only workaround was n_jobs=1. _get_mp_shared() now creates the Manager best-effort: on failure it leaves all module globals untouched (no half-initialized state, no bumped refcount, half-started Manager shut down) and returns None, so _resolve_shared() degrades to the thread-safe DEFAULT_SHARED_* progress path. Because the assign / pre-filter dispatch uses joblib's process backend, a new _worker_shared() helper hands Manager proxies to workers unchanged (byte- identical happy path) but passes None for the thread-safe fallbacks (a threading.Lock cannot be pickled to a spawned process) so each worker self-resolves its own process-local progress and the run completes. Progress is cosmetic-only; output is unchanged when the Manager is available. Adds tests/unit/cpp_tests/test_progress_backend.py covering the Manager failure/degradation arm, clean-globals invariant, resolve fallback, and an end-to-end CPP.run(n_jobs=2) under a forced Manager failure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #348 +/- ##
=======================================
Coverage 94.83% 94.83%
=======================================
Files 196 196
Lines 18767 18787 +20
Branches 3175 3177 +2
=======================================
+ Hits 17797 17817 +20
- Misses 633 635 +2
+ Partials 337 335 -2
🚀 New features to boost your workflow:
|
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.
Closes #339.
Summary
CPP.run(..., n_jobs>1)crashed in non-interactive contexts (python -c, heredocs, some subprocessshells) where
multiprocessing.Manager()raisedEOFError/OSErrorwhile setting up thecross-process progress bar. The only workaround was
n_jobs=1.Details
_get_mp_shared()now creates the Manager best-effort: on failure it leaves all module globalsuntouched (no half-initialized state, no bumped refcount, half-started Manager shut down) and
returns
None, so_resolve_shared()degrades to the thread-safeDEFAULT_SHARED_*progress path._worker_shared()helper hands Manager proxies to workers unchanged (byte-identical happy path) but passes
Noneforthe thread-safe fallbacks (a
threading.Lockcannot be pickled to a spawned process), so eachworker self-resolves its own process-local progress and the run completes.
Ripple
tests/unit/cpp_tests/test_progress_backend.py— Manager failure/degradation arm, clean-globalsinvariant, resolve fallback, and an end-to-end
CPP.run(n_jobs=2)under a forced Manager failure.Part of epic #336.
🤖 Generated with Claude Code