0

I'm currently using Jython embedded in an application and from it I am using a subprocess call to call a Python script that relies on libraries that aren't compatible with Jython to do calculations and return data that will be used inside the application.

Right now I can confirm that ans = subprocess.check_output(command) does get me the correct answer (which is a tuple of 3 large nxn arrays) as a string, which i could parse and store in arrays or a dictionary, but it's incredibly slow to do this.

Surely there is a way to pass object between python scripts correct? It appears my Jython has access to pickle, so I'm leaning towards that direction if someone doesn't have a better idea.

Grant Williams
  • 1,469
  • 1
  • 12
  • 24
  • 1
    You could setup a client/server model and use the multiprocessing managers to pass info. I not positive this will work between Jython and Python but I suspect it will. See... https://stackoverflow.com/questions/47837206/sharing-a-complex-python-object-in-memory-between-separate-processes/48326778#48326778 – bivouac0 Jan 24 '18 at 03:29
  • @bivouac0, if im understanding your post correctly, I'll setup a server with the python code that i'll start with a subprocess from Jython which will setup the server, run the calculations i need from the python file and serve that to the client, which will be implemented in Jython? – Grant Williams Jan 24 '18 at 15:35
  • I was thinking more along the lines of a server that runs continuously and responds to commands from Jython (does your task and passes back data) with no need to call subprocess at all. The code, as written was made to work that way. Potentially you could start it with a Jython call on startup and ask it to exit when Jython exits but I think starting and stopping it a lot would create some unneeded overhead not to mention potential coordination issues (ie.. servers still running when you're trying to start another). – bivouac0 Jan 24 '18 at 15:48
  • So start the server from Jython whenever the java application starts and use the client to add data to a queue (or whatever) from Jython that the Python script can pull, process, and add back to the queue for Jython to pull once again and use in the application? – Grant Williams Jan 24 '18 at 15:54
  • Mostly, however I'll point out that the code I referenced uses function calls via the "proxy" class that is a go-between from client to server. Inside your Jython code a call to the server's functions will look like call to any other local function with data returned at the end. A slightly different way to go would be to implement a client/server directly using sockets. For this you would probably implement a queuing system on top of the socket. – bivouac0 Jan 24 '18 at 16:11
  • @bivouac0, looks like Jython doesnt support multiprocessing but does have low level support for the socket library, so I'll have to dig in a little deeper there instead. Thanks for the advice! – Grant Williams Jan 24 '18 at 16:19

0 Answers0