Mercurial > cpython-lru_cache-weakref
diff Python/_warnings.c @ 86771:1787277915e9
Issue #19442: Fix warnings emitted during Python shutdown
Warnings may be emitted during Python shutdown, like "unclosed file XXX".
During shutdown, globals()['__main__'] may be None.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Wed, 30 Oct 2013 00:04:59 +0100 |
| parents | c7326aa0b69c |
| children | 9b37fbda9043 |
line wrap: on
line diff
--- a/Python/_warnings.c Tue Oct 29 23:58:05 2013 +0100 +++ b/Python/_warnings.c Wed Oct 30 00:04:59 2013 +0100 @@ -540,7 +540,7 @@ } else { *filename = NULL; - if (PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) { + if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) { PyObject *argv = PySys_GetObject("argv"); /* PyList_Check() is needed because sys.argv is set to None during Python finalization */ @@ -564,8 +564,8 @@ else { /* embedded interpreters don't have sys.argv, see bug #839151 */ *filename = PyUnicode_FromString("__main__"); - if (*filename == NULL) - goto handle_error; + if (*filename == NULL) + goto handle_error; } } if (*filename == NULL) { @@ -621,8 +621,15 @@ if (!setup_context(stack_level, &filename, &lineno, &module, ®istry)) return NULL; - res = warn_explicit(category, message, filename, lineno, module, registry, - 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); + } Py_DECREF(filename); Py_DECREF(registry); Py_DECREF(module);
