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/Misc/NEWS b/Misc/NEWS
index e1b818d..015ce1f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -691,7 +691,7 @@
 - Issue #8524: Add a detach() method to socket objects, so as to put the socket
   into the closed state without closing the underlying file descriptor.
 
-- Issue #477863: Print a warning at shutdown if gc.garbage is not empty.
+- Issue #477863: Emit a ResourceWarning at shutdown if gc.garbage is not empty.
 
 - Issue #6869: Fix a refcount problem in the _ctypes extension.