sys.exit() doesn't exit
Fredrik Lundh
fredrik at pythonware.com
Wed Oct 20 09:06:54 EDT 1999
Randall Hopper <aa8vb at yahoo.com> wrote:
> |Alternatively, the C code could call PyErr_Print(), which will call
> |exit() when it sees SystemExit.
>
> Thanks. That was the advice I needed.
>
> The wrapped C code doesn't know about Python so propagating exceptions
> through it really isn't practical. I guess the best I can do is propagate
> them across it.
>
> Fortunately, in this particular C wrapper, there are only two C entry
> points inside which a Python callback might be invoked, so I can use
> static-wrapper-variable-hackery to record when exceptions occur, and return
> NULL in the appropriate spots to the controlling Python. It's not pretty,
> but it works.
>
> With Python using return values to signal exceptions, I guess this is this
> is the best I can do.
hint: use PyErr_Occurred() to figure out
if an error occurred down below...
...
PyErr_Clear(); /* to be on the safe side */
mylibrarydosomething(...)
if (PyErr_Occurred())
return NULL; /* flag the python exception */
return Py_BuildValue(...)
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list