Hi folks,
java code:
try(Jep jep = new Jep()) {
jep.runScript("./src/main/python/thread_test.py");
} catch (JepException e) {
e.printStackTrace();
}}
python code:
import threading
import time
import sys
# import thread
def f1():
for i in range(5):
print ("f1...\n")
sys.stdout.flush()
time.sleep(1)
if __name__ == "__main__":
t = threading.Thread(target=f1, args=())
t.setDaemon(True)
t.start()
for t in threading.enumerate():
print (t.getName())
#if t.getName() != "MainThread":
#t._Thread__stop()
#t._stop()
print (threading.enumerate())
When Jep.close() is called, there is a fatal error:
Fatal Python error: Py_EndInterpreter: not the last thread.
it seems that pyembed_thread_close() should not call Py_EndInterpreter() before all the daemon threads are close.
if (jepThread->tstate->interp == mainThreadState->interp) {
PyThreadState_Clear(jepThread->tstate);
PyThreadState_Swap(NULL);
PyThreadState_Delete(jepThread->tstate);
} else {
Py_EndInterpreter(jepThread->tstate);
}