[New-bugs-announce] [issue30560] Py_SetFatalErrorAbortFunc: Allow embedding program to handle fatal errors

Thomas Perl report at bugs.python.org
Sat Jun 3 15:15:43 EDT 2017


New submission from Thomas Perl:

In our application that embeds a Python interpreter, we had the issue that certain system configurations (namely, a lone "libpython27.dll" without any standard library) caused silent failures (note that this is using Python 2.7, but Python 3.x would be similarly affected, as the Py_FatalError() handling is still the same):

https://github.com/gpodder/gpodder/issues/286

There exists a Stack Overflow thread about this:

https://stackoverflow.com/questions/7688374/how-to-i-catch-and-handle-a-fatal-error-when-py-initialize-fails

The workaround described therein is:

"I solved this by creating a separate executable that attempts to initialize python. My primary process will launch it and check the exit code and only call PyInitialize if the child process was successful. So, python is initialized twice, but it is better than an apparent crash to the user."

So, what if instead we allow the embedding program to set a function pointer to a function that will get called instead of abort()? We have to make clear in the docs that after this function is called, the Python interpreter cannot be used, and the application should probably exit, but at least it would allow applications to capture the error message and show it to the user (e.g. using a MessageBox() on Windows) before exiting -- see attached patch.

Any alternative solutions would be fine as well that don't require us to create a new process and "try to" Py_Initialize() there, especially since Py_FatalError() might potentially be called in other places and in all those cases, a user-visible dialog would be better than an apparent "crash" (application exits).

----------
components: Interpreter Core
files: Py_SetFatalErrorAbortFunc.patch
keywords: patch
messages: 295098
nosy: thomas.perl
priority: normal
severity: normal
status: open
title: Py_SetFatalErrorAbortFunc: Allow embedding program to handle fatal errors
versions: Python 3.6
Added file: http://bugs.python.org/file46921/Py_SetFatalErrorAbortFunc.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30560>
_______________________________________


More information about the New-bugs-announce mailing list