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

Multithreaded python calls to java return deranged results #523

Open
sagewanglun opened this issue Jun 8, 2023 · 5 comments
Open

Multithreaded python calls to java return deranged results #523

sagewanglun opened this issue Jun 8, 2023 · 5 comments

Comments

@sagewanglun
Copy link

Background: Start with the java code and use gunicorn to start the python server with multiple works

The java side uses the following code:
public static void main(String[] args) {
GatewayServer server = new GatewayServer(func);
server.start();

The python side uses the following code:
from py4j.java_gateway import JavaGateway
jvm = JavaGateway()
function = jvm.getfunc()
When multiple threads from python call java, the result will be confused. For example, the input of thread 1 is not returned to thread 1, but to thread 2

@HyukjinKwon
Copy link
Member

Does it use multiprocessing from gunicorn? Py4J is thread-safe but doesn't work well with multiprocessing.

@sagewanglun
Copy link
Author

When will this problem be solved?

@HyukjinKwon
Copy link
Member

If this is from multiprocessing, it would not be fixed because Py4J does not support multiprocessing by design.

@sagewanglun
Copy link
Author

I tried using gunicorn to start a work to start a python method, that is, a single process, and then the python method used multiple threads to call java, but it still returned confusing results. Am I doing it wrong?

@HyukjinKwon
Copy link
Member

Would be great if there's a reproducer without gunicorn to investigate this further. My guts say gurnicorn uses a separate process when you use Py4J.

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