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.

Can joblib.Parallel work in interactive environments (e.g., IPython Notebook) in Windows?

See original GitHub issue

The doc example

from joblib import Parallel, delayed
Parallel(n_jobs=2)(delayed(sqrt)(i ** 2) for i in range(10))

worked with importable functions like sqrt, but not with those defined in interactive environments including IPython Notebook and IPython console:

def myfunc(x):
    return sqrt(x)
Parallel(n_jobs=2)(delayed(myfunc)(i ** 2) for i in range(10))

and raised the following error:

AttributeError: 'module' object has no attribute 'myfunc'

I’m running Python 2.7.7, Anaconda 2.0.1 (64-bit), Windows 7 SP1 (64-bit), IPython 2.1.0, joblib 0.8.4. The same works smoothly in Linux.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:27 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
ogriselcommented, Jul 12, 2021
image
2reactions
lestevecommented, Aug 25, 2016

AFAIR this is not expected to work under Windows neither with Python 2 nor Python 3.

@GaelVaroquaux 2.7. It can be solved by putting the method into module and then import them. But that really complicated the code sometimes…

Putting the method in a module is the cleanest work-around. If that helps, you have a built-in editor in Jupyter these days. If you insist of having all your code in the same notebook you can use a combination of %%file to write into an external file and imp.reload to make sure you always use the latest version of the module.

For completeness, the long-term fix for this is to use dill to serialize the function inside Parallel. The idea would be to just take #240 and only use dill to serialise the function inside Parallel. This is something we really want to do so that we can switch to fork_server as the default joblib start method. We just haven’t had the time to do it … PR more than welcome !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Embarrassingly parallel for loops - Joblib - Read the Docs
Parallel uses the 'loky' backend module to start separate Python worker processes to ... In this case joblib will automatically use the "threading"...
Read more >
Use joblib - Python Numerical Methods
We can see the parallel part of the code becomes one line by using the joblib library, which is very convenient. The Parallel...
Read more >
Print from within Joblib Parallel function in Jupyter notebook
Is it possible to print things or debug when using Parallel in a Jupyter notebook. Here is my code import pandas as pd...
Read more >
joblib Documentation - Read the Docs
The vision is to provide tools to easily achieve better performance and reproducibility when working with long running jobs.
Read more >
Multiprocessing in Python on Windows and Jupyter/Ipython
This code should work perfectly fine on linux, but, If you run it on python shell on Windows (cmd → python), you will...
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