Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
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 1 hour ago
    
That would be an option. I would have to setup a server from python I guess like here stackoverflow.com/questions/20913440/… –  dorien 49 mins ago
    
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 46 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.