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

When using multiple processes, _javabridge.get_env () gets None #181

Open
guojixu opened this issue May 27, 2020 · 2 comments
Open

When using multiple processes, _javabridge.get_env () gets None #181

guojixu opened this issue May 27, 2020 · 2 comments

Comments

@guojixu
Copy link

guojixu commented May 27, 2020

I want to use python to call weka in parallel, but weke_python_wrapper3 uses javabridge, and javabridge is None in sub_f. It is not clear why.
follow code is a demo to show the problem I mentioned。

from joblib import Parallel, delayed
import weka.core.jvm as jvm

import javabridge._javabridge as _javabridge
def sub_f(j):
    print(jvm.started)
    print(_javabridge.get_env())
    print(j)
def joblib_process():

    print(jvm.started)
    print(_javabridge.get_env())

    res = Parallel(n_jobs=6, require='sharedmem')(
            delayed(sub_f)(i) for i in range(6)
        )

    return res

if __name__ == '__main__':
    jvm.start()
    joblib_process()
    jvm.stop()

image

@LeeKamentsky
Copy link
Owner

I am guessing the problem is the process model for joblib. Maybe Javabridge isn't open in the subprocess? See #176 for a tested multiprocess mechanism using Javabridge.

@guojixu
Copy link
Author

guojixu commented May 28, 2020

I am guessing the problem is the process model for joblib. Maybe Javabridge isn't open in the subprocess? See #176 for a tested multiprocess mechanism using Javabridge.

Thank you for your reply. As you said, the problem is in the process of parallelization. Now that the problem has been solved, thank you very much for your guidance.
Below is my corrected code.

    with parallel_backend("multiprocessing", n_jobs=6):
        res = Parallel(require='sharedmem')(delayed(sub_f)(j) for j in range(6))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants