summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-24 15:11:22 (GMT)
committerGeorg Brandl <georg@python.org>2010-10-24 15:11:22 (GMT)
commit08be72d0aa0112118b79d271479598c218adfd23 (patch)
tree5c885e7f573248c725915ed00f4a0476daa7a556 /Modules
parent872a702bbd3c471278e07d773f7a5a49eb9dc5b2 (diff)
downloadcpython-08be72d0aa0112118b79d271479598c218adfd23.zip
cpython-08be72d0aa0112118b79d271479598c218adfd23.tar.gz
cpython-08be72d0aa0112118b79d271479598c218adfd23.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/gcmodule.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index a95bec7..3f96c42 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -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"
- );
- }
}
}