Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1
See original GitHub issueWhat is the reason of such issue in joblib? 'Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1'
What should I do to avoid such issue?
Actually I need to implement XMLRPC server which run heavy computation in background thread and report current progress through polling from UI client. It uses scikit-learn which are based on joblib.
P.S.: I’ve simply changed name of the thread to “MainThread” to avoid such warning and everything looks working good (run in parallel as expected without issues). What might be a problem in future for such workaround?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Multiprocessing backed parallel loops cannot be nested ...
'Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1' What should I do to avoid such issue?
Read more >Embarrassingly parallel for loops - Joblib - Read the Docs
Joblib provides a simple helper class to write parallel for loops using multiprocessing. The core idea is to write the code to be...
Read more >Using n_jobs under a Celery task throws joblib/Loky warning
UserWarning: Loky-backed parallel loops cannot be called in a multiprocessing, setting n_jobs=1 n_jobs = min(effective_n_jobs(n_jobs), ...
Read more >Parallel Nested For-Loops in Python
When using thread pools in one process, the pool can be shared with tasks and subtasks as a shared global variable, allowing tasks...
Read more >8.3. Parallelism, resource management, and configuration
Joblib is able to support both multi-processing and multi-threading. ... copies of some estimators or functions in parallel (see oversubscription below).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

While using multiprocessing below threads is not supported, the current test to detect it relies on the thread name being equal to
MainThreadwhich can produce false positives.For instance, I’m trying to use joblib parallel inside uWSGI (in a non multi-threaded setup). Different workers use a single thread, but the default thread name is something of the form
uWSGIWorker2Core0, and renaming the thread name toMainThreadappears to make everything work fine (same as for the OP), though I hope this doesn’t break anything in uWSGI.As suggested in this SO answer, a more robust testing for multiprocessing nested under threads in joblib could be,
instead of the currently used,
For my uWSGI setup, the latter evaluates to
False, while the former isTrue.This was fixed a long time ago and renaming the thread to
MainThreadshould no longer be necessary. Please open a new issue of you still encounter difficulties with this.