How can I catch and handle a fatal error when Py_initialize fails?

I am implementing python in a C ++ dll (so that in the end I can put it in xll). When the setting is incorrect, Py_Initialize is documented as a permanent failure - see http://docs.python.org/c-api/init.html , "... this is a fatal error if the initialization fails.".

Is it possible to catch this error and how?

You think maybe a global window hook?

+4
source share
3 answers

I solved this by creating a separate executable that is trying to initialize python. My main process will run it and check the exit code and only call PyInitialize if the child process was successful. Thus, python is initialized twice, but it is better than the apparent failure for the user.

+1
source

A fatal error is caused by a call to Py_FatalError , which says goodbye to the explanatory message, and then calls abort() .

+3
source

At the moment, Jason's solution seems to be the only way, but this does not apply to cases where Python fails due to a fatal error somewhere later after Py_Initialize() , so there is no way for the implementation application to handle it in a more graceful way (show message GUI and only then abort).

I created a fix and a problem in Python, cross referencing this question: http://bugs.python.org/issue30560

+1
source

All Articles