1

I fiddled around with calling a python script from a Java program for a little while and was finally able to get it working. However, When I called it I noticed that there is a certain call in the python script that creates an object that takes a couple of seconds (which is longer than I'd like). So in an essence every time the script runs it has to re-import a few libraries and create a new object. I'm not sure if this is even possible, but is there any way to keep the python script in a state where it wouldn't have to completely re-run from the start every single time?

Any help would be greatly appreciated. I do not have much experience with the integration of programs with different languages.

Thank you very much!!! Any suggestions are welcome.

2 Answers 2

2

I'm not sure if this is even possible, but is there any way to keep the python script in a state where it wouldn't have to completely re-run from the start every single time?

The correct and most obvious way to do this is to re-implement (if you can) the Python script and turn it into some kind of Remote Serivce and use some kind of Interface:

Examples:

  • Web Service over JSON
  • Web Service over RPC, JSON-RPC, XML-RPC

You would then access the service(s) remotely over a network connection from your Java program and serialize parameters passed to the Python program and theh results back to Java via something both can speak eaisly. e.g: JSON

Sign up to request clarification or add additional context in comments.

1 Comment

I see what you mean there. I guess if I set it up correctly then I could just do something like a GET with a parameter and I would have my result in JSON.
1

Take a look at Google's Protobuf. It is basically a cross-language RPC.

Or open a named pipe between your java and python application

1 Comment

I know what piping is from my experience with UNIX but am not completely sure how I would use it here. This would probably be what I want to do though. Or I have read another possibility is working with Jython. I will take a look at these options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.