Reject n_jobs=0 in MultiprocessingBackend before the nesting checks - #1838
Open
ckarnell wants to merge 1 commit into
Open
Reject n_jobs=0 in MultiprocessingBackend before the nesting checks#1838ckarnell wants to merge 1 commit into
ckarnell wants to merge 1 commit into
Conversation
ckarnell
force-pushed
the
fix-njobs-zero-daemon
branch
from
August 19, 2026 13:29
134ea20 to
5b4f57b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1838 +/- ##
=======================================
Coverage 94.06% 94.07%
=======================================
Files 46 46
Lines 8070 8082 +12
=======================================
+ Hits 7591 7603 +12
Misses 479 479 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MultiprocessingBackend validates n_jobs last, after the daemon and nesting checks, so in a daemonic process effective_n_jobs(0) returns 1 with a nesting warning instead of raising, unlike the other three backends. Add the n_jobs==0 check at the top (additive, reorders nothing). Adds test_invalid_njobs_in_daemon_process, going through the public effective_n_jobs because Parallel recovers and hides the defect.
ckarnell
force-pushed
the
fix-njobs-zero-daemon
branch
from
August 19, 2026 14:31
5b4f57b to
47c17de
Compare
Contributor
|
LGTM. As some users might currently use the |
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.
SequentialBackend,PoolManagerMixinandLokyBackendall rejectn_jobs=0as their first act.MultiprocessingBackendgets there last, after the daemon and nesting checks, so in a daemonic process the invalid value is swallowed and reported as a nesting problem instead.The other three raise there.
ValueError: n_jobs == 0 in Parallel has no meaning.effective_n_jobsis public and in__all__, so this is the documented error going missing on one backend.test_invalid_njobsalready asserts the behaviour for every backend and passes today, because it goes throughParallel. When the backend returns 1,configureraisesFallbackToBackend(SequentialBackend(...)), and the sequential backend then raises for its own reasons. The error a caller sees is right, and it's arriving from a different backend than the one they asked for.Three lines. Nothing moves. The check is added at the top instead of reordering what's there, so the daemon and nesting branches behave exactly as before for every valid
n_jobs.Test is
test_invalid_njobs_in_daemon_process, parametrized over the four backends and going through the publiceffective_n_jobsinstead ofParallel, sinceParallelrecovers and hides it. Reverting_parallel_backends.pyfails it onmultiprocessingalone with DID NOT RAISE, and the other three pass either way.test_parallel.pyis 575 passed, 24 skipped, 3 xpassed, against 574 and the one failure on revert.