[issue45033] Calls to PyErr_PrintEx in destructors cause calling async functions to incorrectly return None

Andrew Svetlov report at bugs.python.org
Wed Mar 9 21:05:52 EST 2022


Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:

'catch (boost::python::error_already_set e)' is equal to `except BaseException as e:`
In Python, blind catching base exception is dangerous, the code should re-raise it usually.
The same is true for boost::python usage.

> how would it tell the difference between a "real" exception raised from within whatever function is currently returning and the "fake" StopIteration exception that is in the error global while an async function returns?

There is no "fake" exception. async function is a kind of Python generator object that uses StopIteration exception for finishing.
The same is true for a regular Python iterator; nothing asyncio specific.

I suggest writing a functional equivalent for `except Exception as e: print(e)` instead of catching BaseException error.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45033>
_______________________________________


More information about the Python-bugs-list mailing list