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

getting an exception when starting the JVM on a server #180

Open
raedtjr opened this issue Dec 14, 2015 · 5 comments
Open

getting an exception when starting the JVM on a server #180

raedtjr opened this issue Dec 14, 2015 · 5 comments

Comments

@raedtjr
Copy link

raedtjr commented Dec 14, 2015

I have created an application using py4j that makes it possible to save data from python in to SQL database using a java application,everything works so fine when i run the JVM as an application and it actually saves the data. But when i run the code in a server it gives me back an exception.Therfore i thought maybe my server(Wildfly) and Py4j are using the same port so i changed the default py4j port as the turotial suggested but i m still having an exception:

Traceback (most recent call last):
File "C:\Users\user\Desktop\test.py", line 4, in
DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(10,3)
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 1185, in getattr
answer = self._gateway_client.send_command(
AttributeError: 'GatewayParameters' object has no attribute 'send_command'

Any suggestions would be very much appreciated

@bartdag
Copy link
Collaborator

bartdag commented Dec 15, 2015

Hi, can you post how you created your JavaGateway instance and how you are accessing it? It seems that the constructor parameters are wrong.

Also, which version of Py4J are you using locally and on your server?

@raedtjr
Copy link
Author

raedtjr commented Dec 15, 2015

Hi,
Thank you for your replay.
So this is what i wrote in python. Please read the comment it my help to explain the situation.

from py4j.java_gateway import JavaGateway, GatewayParameters
gateway = JavaGateway(GatewayParameters(port=25335)) #when i dont use gatewayParameters everything works and i can save data in the BD using the java application i creat.
 testBD = gateway.entry_point
 DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(10,3) #calling constructor from class application
  testBD.create(DBin)#Executing the method create to inject in the database

Now this is what i creat in the main class in java :

public static void main(String[] args) {
    StoreData app=new StoreData();
    GatewayServer gatewayServer = new GatewayServer(app, 25335);// when i dont use the port specification in both side it works only when i run the application locally but as soon as i turn on the wildfly server,the connection fail
    gatewyServer.start();

}

And this is the exceptions i get when i run the code in wildfly and i try to execute the java code from python:

Traceback (most recent call last):
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 577, in _get_connection
connection = self.deque.pop()
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 690, in start
self.socket.connect((self.address, self.port))
ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\user\Desktop\test.py", line 4, in <module>
DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(1,1) #calling constructor from class application
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 1188, in __getattr__
"\n" + proto.END_COMMAND_PART)
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 624, in send_command
connection = self._get_connection()
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 579, in _get_connection
connection = self._create_connection()
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 585, in _create_connection
connection.start()
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 697, in start
raise Py4JNetworkError(msg, e)
py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server
>>> 

For the Py4j version i used easy_install for the installation on python
and for eclipse i used this link: https://eclipse.py4j.org/
Thank you alot for your help.

@bartdag
Copy link
Collaborator

bartdag commented Dec 15, 2015

Try to replace gateway = JavaGateway(GatewayParameters(port=25335)) by gateway = JavaGateway(gateway_parameters=GatewayParameters(port=25335)). As stated in the JavaGateway documentation, the first parameter is a GatewayClient (deprecated) and the gateway parameters is the second to last parameter.

The exception you are seeing is because the python process cannot connect to the Java process.

@raedtjr
Copy link
Author

raedtjr commented Dec 15, 2015

Thank you for the suggestion.
I just tried it out but it gives me back this exception:

  Traceback (most recent call last):
   File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-        py3.5.egg\py4j\java_gateway.py", line 577, in _get_connection
  connection = self.deque.pop()
  IndexError: pop from an empty deque

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-  py3.5.egg\py4j\java_gateway.py", line 690, in start
  self.socket.connect((self.address, self.port))
  ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der           Zielcomputer die Verbindung verweigerte

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "C:\Users\user\Desktop\test.py", line 4, in <module>
 DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(2,2) #calling constructor from class application
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 1188, in __getattr__
"\n" + proto.END_COMMAND_PART)
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 624, in send_command
 connection = self._get_connection()
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 579, in _get_connection
 connection = self._create_connection()
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 585, in _create_connection
 connection.start()
 File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 697, in start
 raise Py4JNetworkError(msg, e)
 py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server
 >>> 

I dont know if the problem is related to the port or not. Maybe it is related to the address localhost (127.0.0.1) which is used by py4j for listens to the IPv4 and this address is also in used by the wildfly server.

@bartdag
Copy link
Collaborator

bartdag commented Dec 24, 2015

Both servers can listen on the same address as long as they use different port. Can you post, maybe in a gist, most of the python and java code that handles the connection? The IndexError pop from empty queue is very strange and this is the first time I see it with adequate parameters.

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

No branches or pull requests

2 participants