Repository navigation
Fix mrun hanging when a worker dies and leaking process pools - #1156
Merged
rkingsbury merged 2 commits intoOct 27, 2026
Merged
Conversation
- AsyncUnorderedMap now raises BrokenProcessPool (or any error from the source iterator) from iteration instead of waiting forever. Per-item executor failures such as unpicklable items are logged and skipped like errors inside process_item, so they no longer leak a back-pressure slot. - Gather the per-item wrapper tasks rather than the raw futures, so the done sentinel cannot overtake the last result, and keep references to them (resolves the RUF006 TODO). - multi() always shuts down its ProcessPoolExecutor, including on error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Pt7k5BrMjWxfc4edxL6mg
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1156 +/- ##
==========================================
+ Coverage 69.77% 69.92% +0.15%
==========================================
Files 47 47
Lines 4106 4120 +14
==========================================
+ Hits 2865 2881 +16
+ Misses 1241 1239 -2 ☔ View full report in Codecov by Harness. 🚀 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.
Summary
Fixes two long-standing bugs in the
mrun -n Nmultiprocessing runner (src/maggma/cli/multiprocessing.py), found while looking into the Python 3.14 CI hang (materialsproject/maggma#1151).Major changes:
mrun. When a worker crashed or was OOM-killed,AsyncUnorderedMapswallowed theBrokenProcessPoolerror and the fill task died without ever posting its "done" sentinel, so the consumer waited on the results queue forever. Now anyBrokenExecutor, or any exception raised by the source iterator (e.g. a failing cursor), is raised from iteration and propagates out ofmulti().safe_dispatchalready handles errors insideprocess_item. Before, they were silently dropped and never released their back-pressure slot, so afterchunk_sizeof them the run also hung.RUF006TODO).==tois, so result objects with a custom__eq__(numpy, pandas) can't break it.multi()created aProcessPoolExecutorand never shut it down. Each leaked pool kept its management thread alive, and forking new pools while those threads were running is a known cause of intermittent deadlocks (e.g. severalmrun -n 2calls in one pytest process). The executor is now shut down in afinallywithcancel_futures=True, both on success and on error.Todos
test (3.14)job should be checked again.Checklist
ruff. (pre-commit runpasses on the changed files.)mypy. (I didn't add annotations, to match the surrounding code.)os._exitraisesBrokenProcessPool, a failing source iterator raises, an unpicklable item is skipped, andmulti()shuts down its executor both on success and whenupdate_targetsraises. All four time out or fail onmain.tests/cli/test_multiprocessing.pypasses on 3.13 (with both fork and forkserver start methods) and on 3.14. The non-Mongomrun -n 2tests intest_init.pyalso pass. I couldn't run the Mongo-backed tests locally because nomongodwas available, so CI covers those.🤖 Generated with Claude Code