diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-31 23:55:30 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-31 23:55:30 (GMT) |
commit | dcdd05b0b4c23da0eb39d3b29d40f8865b6b73ee (patch) | |
tree | fa2fef4ac1c4523ce295bf7e7f24bc99777f7e28 | |
parent | 6ec518bd8efd991412009392eefca8ef091198a3 (diff) | |
download | cpython-dcdd05b0b4c23da0eb39d3b29d40f8865b6b73ee.zip cpython-dcdd05b0b4c23da0eb39d3b29d40f8865b6b73ee.tar.gz cpython-dcdd05b0b4c23da0eb39d3b29d40f8865b6b73ee.tar.bz2 |
Close #19442: warn_explicit() does nothing when called late during Python shutdown
After more tests, I now think that it is the safest option.
-rw-r--r-- | Python/_warnings.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index d9f3297..e88f646 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -333,6 +333,13 @@ warn_explicit(PyObject *category, PyObject *message, PyObject *action; int rc; + /* module can be None if a warning is emitted late during Python shutdown. + In this case, the Python warnings module was probably unloaded, filters + are no more available to choose as action. It is safer to ignore the + warning and do nothing. */ + if (module == Py_None) + Py_RETURN_NONE; + if (registry && !PyDict_Check(registry) && (registry != Py_None)) { PyErr_SetString(PyExc_TypeError, "'registry' must be a dict"); return NULL; @@ -635,15 +642,8 @@ do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level) if (!setup_context(stack_level, &filename, &lineno, &module, ®istry)) return NULL; - if (module != Py_None) { - res = warn_explicit(category, message, filename, lineno, module, registry, - NULL); - } - else { - /* FIXME: emitting warnings at exit does crash Python */ - res = Py_None; - Py_INCREF(res); - } + res = warn_explicit(category, message, filename, lineno, module, registry, + NULL); Py_DECREF(filename); Py_DECREF(registry); Py_DECREF(module); |