ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

Tests freeze in python 3.9.9 #359

Closed bsteffensmeier closed 2 years ago

bsteffensmeier commented 2 years ago

When I try to build jep against python 3.9.9 the test hang and never complete. I have traced it to calling sys.exit(0) in a test. We may be able to work around this by removing that call from the test but I have also noticed sys.exit() will freeze an interactive interpreter, which might be a problem.

We have some code for handling the exit but it just calls PyErr_PrintEx() to handle the exit. I traced through PyErr_PrintEx() and found that the freeze occurs in threading._shutdown(). That function was recently changed in a python bug and I believe that change is what is causing the problem.

The problem does not exist in earlier versions of python 3.9. It does not exist in python 3.10.0 but the change was merged into the 3.10 branch so it will likely affect 3.10 whenever the next python version is released.

bsteffensmeier commented 2 years ago

In #361 I have changed the behavior so that we will call exit() ourselves in native code rather than relying on python to exit.

In the future I think we need to stop handling SystemExit specially and allow it to be wrapped as a JepException and handled in java. For Run.java we would like to catch that exception and exit from java but that will require a new mechanism for getting the exit code from a SystemExit wrapped in a JepException so there is more work to do.

ndjensen commented 2 years ago

This is fixed in Jep 4.0.1.