1

I need to call a python function from java, pass it an array, and get an array back. I realise I can do this with Jython.

The problem is, my python script needs to load a very heavy (and slow to load) model in order to run the function. So I was wondering if I could leave the python script on somehow, and let it listen to the next function call. Any ideas on this? I could have the java i/o files and communicate like this, but this seems like a (smaller though) bottleneck as well.

I read something about multiprocessing in python, but I am not sure this is the way to go https://docs.python.org/3/library/multiprocessing.html#multiprocessing-managers

dorien
  • 5,265
  • 10
  • 57
  • 116
  • 1
    Why not communicate through a socket? Have python listen to a socket, serialize your data (I recommend JSON) and pass it using the socket from Java to python. – Reut Sharabani Dec 02 '14 at 14:41
  • That would be an option. I would have to setup a server from python I guess like here http://stackoverflow.com/questions/20913440/connecting-python-socket-and-java-socket – dorien Dec 02 '14 at 15:33
  • There are plenty of examples all over the internet. You can utilize existing protocols to pass more complex messages. But if you plan on keeping it simple making your own implementation is great. – Reut Sharabani Dec 02 '14 at 15:36

1 Answers1

0

I was able to keep the python script running by setting up a python socks server and a java client to communicate.

dorien
  • 5,265
  • 10
  • 57
  • 116