bpo-36829: Add sys.unraisablehook() by vstinner · Pull Request #13187 · python/cpython
Add new sys.unraisablehook() function which can be overriden to control how "unraisable exceptions" are handled. It is called when an exception has occurred but there is no way for Python to handle it. For example, when a destructor raises an exception or during garbage collection (gc.collect()). Changes: * The default hook now ignores exception on writing the traceback. * Add an internal UnraisableHookArgs type used to pass arguments to sys.unraisablehook. * Add _PyErr_WriteUnraisableDefaultHook(). * test_sys now uses unittest.main() to automatically discover tests: remove test_main(). * Add _PyErr_Init(). * Fix PyErr_WriteUnraisable(): hold a strong reference to sys.stderr while using it
* Rename 'exc_tb' field to 'exc_traceback' * Rename 'obj' field to 'object' * Fix PyErr_WriteUnraisable(): don't call sys.unraisablehook if exc_type is NULL (this case should not happen) * Documentation: add links between sys.excepthook and sys.unraisablehook
This was referenced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters