question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiprocessing backed parallel loops cannot be nested below threads, setting n_jobs=1

See original GitHub issue

What 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:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
rthcommented, Oct 12, 2016

While using multiprocessing below threads is not supported, the current test to detect it relies on the thread name being equal to MainThread which 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 to MainThread appears 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,

isinstance(threading.current_thread(), threading._MainThread))

instead of the currently used,

threading.current_thread().name == 'MainThread'

For my uWSGI setup, the latter evaluates to False, while the former is True.

0reactions
rthcommented, Jul 10, 2019

This was fixed a long time ago and renaming the thread to MainThread should no longer be necessary. Please open a new issue of you still encounter difficulties with this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found