Open Loc300 opened 3 months ago
This is not the expected behavior but it can be very difficult to identify whether this is a problem with jep or with one of the libraries you are using. If possible I recommend running your test without any imports and verify jep works with the base python interpreter. If that works then it is likely this isn't a problem with jep but rather a problem with one of the libraries. If a library holds state information about an interpreter in native memory then it may not be possible to use the library in multiple interpreters, In this case you may need to maintain a single SharedInterpreter for use whenever you access the library.
I´m using Jep in my Java Gradle project and use it to predict with pytorch neural network.
My initialising looking like that
public class Test { private SharedInterpreter interp = new SharedInterpreter(); public Test() throws IOException { interp.eval("import sys"); interp.eval("sys.path.append('')"); interp.runScript("/Users/test.py"); } }
When I initialize the class for the very first time and execute my prediction, everything works so far. The line for the prediction is pretty muchObject result = interp.invoke("predict_test", params);
So i can run my predict and train functions as often as i like, for that first SharedInterpreter instance. After i´m done with the training is use
interp.close()
. To avoid the error here:So in my case after one succesful training, im creating a new instance of the
Test
class. And when im using my prediction function again, im getting the following error:When i dont create a new instance of the
Test
class, the functions work very well.Am i missing something?
Environment (please complete the following information): Im Using an M1 Macbook Pro
Sonoma 14.4 (23E214) Python 3.11 JEP==4.2.0 Python packages are mostly pytorch, numpy, logging and json