mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
On ResourceWarning, log traceback where the object was allocated
Issue #26567: * Add a new function PyErr_ResourceWarning() function to pass the destroyed object * Add a source attribute to warnings.WarningMessage * Add warnings._showwarnmsg() which uses tracemalloc to get the traceback where source object was allocated.
This commit is contained in:
parent
1231a4615f
commit
914cde89d4
11 changed files with 175 additions and 40 deletions
|
@ -92,8 +92,7 @@ fileio_dealloc_warn(fileio *self, PyObject *source)
|
|||
if (self->fd >= 0 && self->closefd) {
|
||||
PyObject *exc, *val, *tb;
|
||||
PyErr_Fetch(&exc, &val, &tb);
|
||||
if (PyErr_WarnFormat(PyExc_ResourceWarning, 1,
|
||||
"unclosed file %R", source)) {
|
||||
if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
|
||||
/* Spurious errors can appear at shutdown */
|
||||
if (PyErr_ExceptionMatches(PyExc_Warning))
|
||||
PyErr_WriteUnraisable((PyObject *) self);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue