Martin Landa <landa.mar...@gmail.com> wrote: > Hi all, > > in my python application I am calling functions from a C library via > `ctypes` interface. Some fns from that C library calls `exit()` on > error. It causes that the python application crashes even without any > notification. Is it possible to catch library system exit calls from > such python application? > > Thanks in advance, Martin
There is no safe way to do this. An unsafe way would be to install an atexit() handler and longjmp out of it, but that would mess up any other atexit processing and quite likely crash the program. Or you could just move the essential cleanup into atexit() but not attempt to stop the program termination. The clean (but not necessarily easy) solution would be to move all of the code that uses the library into a separate subprocess and then you can catch and handle the subprocess exiting in your main code. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list