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

Closed
mgbckr opened this Issue Jan 15, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@mgbckr
Copy link

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

args=5
def func():
    return args

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

Update:

I am using Ubuntu:

NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Kernel:

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

@pierreglaser

This comment has been minimized.

Copy link
Contributor

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.).

@mgbckr

This comment has been minimized.

Copy link
Author

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.

@ogrisel

This comment has been minimized.

Copy link
Contributor

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