mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +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
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue