summaryrefslogtreecommitdiffstats
path: root/Lib
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 /Lib
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 'Lib')
-rw-r--r--Lib/test/exception_hierarchy.txt1
-rw-r--r--Lib/test/test_gc.py8
-rw-r--r--Lib/warnings.py7
3 files changed, 13 insertions, 3 deletions
diff --git a/Lib/test/exception_hierarchy.txt b/Lib/test/exception_hierarchy.txt
index 73ccb66..5037b33 100644
--- a/Lib/test/exception_hierarchy.txt
+++ b/Lib/test/exception_hierarchy.txt
@@ -47,3 +47,4 @@ BaseException
+-- ImportWarning
+-- UnicodeWarning
+-- BytesWarning
+ +-- ResourceWarning
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index 6c8907d..9de7c29 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -485,7 +485,7 @@ class GCTests(unittest.TestCase):
gc.set_debug(%s)
"""
def run_command(code):
- p = subprocess.Popen([sys.executable, "-c", code],
+ p = subprocess.Popen([sys.executable, "-Wd", "-c", code],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
@@ -494,11 +494,13 @@ class GCTests(unittest.TestCase):
return strip_python_stderr(stderr)
stderr = run_command(code % "0")
- self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
+ self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
+ b"shutdown; use", stderr)
self.assertNotIn(b"<X 'first'>", stderr)
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
- self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
+ self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
+ b"shutdown", stderr)
self.assertTrue(
(b"[<X 'first'>, <X 'second'>]" in stderr) or
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
diff --git a/Lib/warnings.py b/Lib/warnings.py
index a81aab3..5b5821b 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -383,4 +383,11 @@ if not _warnings_defaults:
else:
bytes_action = "ignore"
simplefilter(bytes_action, category=BytesWarning, append=1)
+ # resource usage warnings are enabled by default in pydebug mode
+ if hasattr(sys, 'gettotalrefcount'):
+ resource_action = "always"
+ else:
+ resource_action = "ignore"
+ simplefilter(resource_action, category=ResourceWarning, append=1)
+
del _warnings_defaults