jpype
jpype copied to clipboard
Catch java.lang.System.exit() call
Is there a way to catch java.lang.System.exit() call so that the process does not stop abruptly ? I am using JPype in a Django application and the connected java app calls System.exit in several methods causing the django server to stop.
I have not tested this myself but I would assume the correct solution is to use a JProxy to implement a SecurityManager and prevent the System.exit().
See https://stackoverflow.com/questions/5549720/how-to-prevent-calls-to-system-exit-from-terminating-the-jvm
JProxy implements interfaces but SecurityManager is a class. How to implement a class in JPype?
Hmm. I will have to test that. It should be possible to proxy a class. One work around would be to just write a class that does the security exception and load it if the proxy does not work.
It is not possible to Proxy a class. Currently the only way to handle this is to create a java class and load it to override the methods. At some point in the future we could create byte code to extend a class from withing python but this it on a long time scale.
This one remains stuck on enhancement #420 which is a long term goal.