Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joblib.Parallel overwrites args variable for n_jobs > 1 #833

mgbckr opened this issue Jan 15, 2019 · 3 comments

joblib.Parallel overwrites args variable for n_jobs > 1 #833

mgbckr opened this issue Jan 15, 2019 · 3 comments


Copy link

@mgbckr mgbckr commented Jan 15, 2019

joblib version: 0.13.0

In the following example, when I set n_jobs>1, then the args from the outer scope will be overwritten by a Paralel namespace for n_jobs=1 this does not happen. Other variable names are not effected. This a) is not consistent and b) generally, I think Parallel should not overwrite any variable. Thanks :)

import joblib

def func():
    return args

joblib.Parallel(n_jobs=2)(joblib.delayed(func)() for i in range(1))


I am using Ubuntu:

VERSION="18.04.1 LTS (Bionic Beaver)"
PRETTY_NAME="Ubuntu 18.04.1 LTS"


Linux 4.15.0-43-generic x86_64
@mgbckr mgbckr changed the title Parallel overwrites args variable for n_jobs > 1 joblib.Parallel overwrites args variable for n_jobs > 1 Jan 15, 2019
Copy link

@pierreglaser pierreglaser commented Jan 16, 2019

I do not know which operating system you are using, but this is likely due to the joblib/externals/loky/backend/popen_*.py file family, that are executed to create new processes that will execute the joblib.delayed calls (when backend="loky"). Prior to actual func calls, the global namespaces of the newly started processes are not completely empty, and you just encountered a collusion.

There are ways to limit the collusions to the bare minimum, but I can't imagine a zero-collusion solution, since some variables such as __name__, __doc__ are set each time a python interpreter is created. So I am not sure it is worth implementing a partial fix.

The least we can do however is documenting which variable names will generate collusions and thus should not be used. There are actually a few more than simply args (parser, exitcode, info, spawn etc.).

Copy link

@mgbckr mgbckr commented Jan 16, 2019

Hi, I added my OS details. I think adding this in a visible way to the documentation of joblib.Parallel (and maybe joblib.delayed?) would be fine.

Copy link

@ogrisel ogrisel commented Feb 7, 2019

I confirm that the fix in cloudpipe/cloudpickle#240 fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants