mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
except when configured --with-pydebug. Emit this warning from the GC shutdown procedure, rather than just printing to stderr.
This commit is contained in:
parent
872a702bbd
commit
08be72d0aa
12 changed files with 80 additions and 30 deletions
|
@ -1368,11 +1368,16 @@ _PyGC_Fini(void)
|
|||
{
|
||||
if (!(debug & DEBUG_SAVEALL)
|
||||
&& garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
|
||||
PySys_WriteStderr(
|
||||
"gc: "
|
||||
"%" PY_FORMAT_SIZE_T "d uncollectable objects at shutdown:\n",
|
||||
PyList_GET_SIZE(garbage)
|
||||
);
|
||||
char *message;
|
||||
if (debug & DEBUG_UNCOLLECTABLE)
|
||||
message = "gc: %" PY_FORMAT_SIZE_T "d uncollectable objects at " \
|
||||
"shutdown";
|
||||
else
|
||||
message = "gc: %" PY_FORMAT_SIZE_T "d uncollectable objects at " \
|
||||
"shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them";
|
||||
if (PyErr_WarnFormat(PyExc_ResourceWarning, 0, message,
|
||||
PyList_GET_SIZE(garbage)) < 0)
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
if (debug & DEBUG_UNCOLLECTABLE) {
|
||||
PyObject *repr = NULL, *bytes = NULL;
|
||||
repr = PyObject_Repr(garbage);
|
||||
|
@ -1387,11 +1392,6 @@ _PyGC_Fini(void)
|
|||
Py_XDECREF(repr);
|
||||
Py_XDECREF(bytes);
|
||||
}
|
||||
else {
|
||||
PySys_WriteStderr(
|
||||
" Use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them.\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue