]> granicus.if.org Git - python/commit
bpo-36829: Add sys.unraisablehook() (GH-13187)
authorVictor Stinner <vstinner@redhat.com>
Wed, 22 May 2019 09:28:22 +0000 (11:28 +0200)
committerGitHub <noreply@github.com>
Wed, 22 May 2019 09:28:22 +0000 (11:28 +0200)
commitef9d9b63129a2f243591db70e9a2dd53fab95d86
tree3ecd9bb04fba6c9d360b8db5d8b1e78cda50d49b
parent2725cb01d7cbf5caecb51cc20d97ba324b09ce96
bpo-36829: Add sys.unraisablehook() (GH-13187)

Add new sys.unraisablehook() function which can be overridden 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:

* Add an internal UnraisableHookArgs type used to pass arguments to
  sys.unraisablehook.
* Add _PyErr_WriteUnraisableDefaultHook().
* The default hook now ignores exception on writing the traceback.
* 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
12 files changed:
Doc/c-api/exceptions.rst
Doc/library/sys.rst
Doc/whatsnew/3.8.rst
Include/internal/pycore_pylifecycle.h
Lib/test/test_sys.py
Misc/NEWS.d/next/Library/2019-05-08-12-51-37.bpo-36829.8enFMA.rst [new file with mode: 0644]
Modules/_testcapimodule.c
Python/clinic/sysmodule.c.h
Python/errors.c
Python/importlib.h
Python/pylifecycle.c
Python/sysmodule.c