jpype icon indicating copy to clipboard operation
jpype copied to clipboard

Catch java.lang.System.exit() call

Open rtgdk opened this issue 7 years ago • 5 comments

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.

rtgdk avatar Aug 04 '17 18:08 rtgdk

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

Thrameos avatar Aug 05 '17 08:08 Thrameos

JProxy implements interfaces but SecurityManager is a class. How to implement a class in JPype?

rtgdk avatar Aug 05 '17 18:08 rtgdk

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.

Thrameos avatar Aug 08 '17 15:08 Thrameos

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.

Thrameos avatar Jul 30 '18 15:07 Thrameos

This one remains stuck on enhancement #420 which is a long term goal.

Thrameos avatar Apr 06 '20 17:04 Thrameos