summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-22 11:28:22 +0200
committerGitHub <noreply@github.com>2019-05-22 11:28:22 +0200
commitef9d9b63129a2f243591db70e9a2dd53fab95d86 (patch)
tree3ecd9bb04fba6c9d360b8db5d8b1e78cda50d49b /Python/pylifecycle.c
parent2725cb01d7cbf5caecb51cc20d97ba324b09ce96 (diff)
downloadcpython-git-ef9d9b63129a2f243591db70e9a2dd53fab95d86.tar.gz
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
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 01344db410..6dc684bfce 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -587,6 +587,12 @@ pycore_init_types(void)
if (!_PyContext_Init()) {
return _Py_INIT_ERR("can't init context");
}
+
+ err = _PyErr_Init();
+ if (_Py_INIT_FAILED(err)) {
+ return err;
+ }
+
return _Py_INIT_OK();
}
@@ -1462,6 +1468,12 @@ new_interpreter(PyThreadState **tstate_p)
return err;
}
+ err = _PyErr_Init();
+ if (_Py_INIT_FAILED(err)) {
+ return err;
+ }
+
+
/* XXX The following is lax in error checking */
PyObject *modules = PyDict_New();
if (modules == NULL) {