◐ Shell
clean mode source ↗

bpo-36829: Add sys.unraisablehook() by vstinner · Pull Request #13187 · python/cpython

serhiy-storchaka

serhiy-storchaka

serhiy-storchaka

serhiy-storchaka

zooba

pablogsal

pablogsal

pablogsal

pablogsal

pablogsal

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
* Fix typo in the doc
* Update PyErr_WriteUnraisable() documentation
* Regenerate importlib.h

This was referenced

May 22, 2019