Catching SystemExit in C API code when embedding Python?
Stefan Bellon
sbellon at sbellon.de
Thu Aug 2 15:29:49 EDT 2007
On Thu, 02 Aug, Farshid Lashkari wrote:
> Also, here is some sample code that will catch system exit exceptions:
>
> //Call python code
> ...
> //Check for system exit exception
> if(PyErr_Occurred()) {
> if(PyErr_ExceptionMatches(PyExc_SystemExit)) {
> //handle system exit
> PyErr_Clear();
> } else {
> PyErr_Print();
> }
> }
Thanks for your hints ...
The interesting part is "Call python code". In my example this is done
with PyRun_SimpleString which does not return if an exception is not
handled but raised "out of" the interpreter. So I am unsure of what you
mean with "Call python code".
When installing an excepthook (see my other posting), then I can indeed
catch all exceptions ... except for SystemExit which is the one I'm
after.
--
Stefan Bellon
More information about the Python-list
mailing list