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.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index b82b6ba..5715b26 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1852,6 +1852,7 @@
"Base class for warnings about Unicode related problems, mostly\n"
"related to conversion problems.");
+
/*
* BytesWarning extends Warning
*/
@@ -1860,6 +1861,13 @@
"related to conversion from str or comparing to str.");
+/*
+ * ResourceWarning extends Warning
+ */
+SimpleExtendsException(PyExc_Warning, ResourceWarning,
+ "Base class for warnings about resource usage.");
+
+
/* Pre-computed MemoryError instance. Best to create this as early as
* possible and not wait until a MemoryError is actually raised!
@@ -1939,6 +1947,7 @@
PRE_INIT(ImportWarning)
PRE_INIT(UnicodeWarning)
PRE_INIT(BytesWarning)
+ PRE_INIT(ResourceWarning)
bltinmod = PyImport_ImportModule("builtins");
if (bltinmod == NULL)
@@ -2001,6 +2010,7 @@
POST_INIT(ImportWarning)
POST_INIT(UnicodeWarning)
POST_INIT(BytesWarning)
+ POST_INIT(ResourceWarning)
PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL);
if (!PyExc_MemoryErrorInst)