mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
[3.14] gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode was set (GH-136518) (#136522)
gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode was set (GH-136518)
(cherry picked from commit c560df9658)
Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
This commit is contained in:
parent
5535482d2a
commit
e03db7317f
3 changed files with 8 additions and 1 deletions
|
|
@ -726,6 +726,9 @@ def run_command(code):
|
||||||
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
|
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
|
||||||
b"shutdown; use", stderr)
|
b"shutdown; use", stderr)
|
||||||
self.assertNotIn(b"<X 'first'>", stderr)
|
self.assertNotIn(b"<X 'first'>", stderr)
|
||||||
|
one_line_re = b"gc: uncollectable <X 0x[0-9A-Fa-f]+>"
|
||||||
|
expected_re = one_line_re + b"\r?\n" + one_line_re
|
||||||
|
self.assertNotRegex(stderr, expected_re)
|
||||||
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
|
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
|
||||||
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
|
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
|
||||||
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
|
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
|
||||||
|
|
@ -733,6 +736,8 @@ def run_command(code):
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
(b"[<X 'first'>, <X 'second'>]" in stderr) or
|
(b"[<X 'first'>, <X 'second'>]" in stderr) or
|
||||||
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
|
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
|
||||||
|
# we expect two lines with uncollectable objects
|
||||||
|
self.assertRegex(stderr, expected_re)
|
||||||
# With DEBUG_SAVEALL, no additional message should get printed
|
# With DEBUG_SAVEALL, no additional message should get printed
|
||||||
# (because gc.garbage also contains normally reclaimable cyclic
|
# (because gc.garbage also contains normally reclaimable cyclic
|
||||||
# references, and its elements get printed at runtime anyway).
|
# references, and its elements get printed at runtime anyway).
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed a typo that prevented printing of uncollectable objects when the
|
||||||
|
:const:`gc.DEBUG_UNCOLLECTABLE` mode was set.
|
||||||
|
|
@ -1763,7 +1763,7 @@ gc_collect_region(PyThreadState *tstate,
|
||||||
Py_ssize_t n = 0;
|
Py_ssize_t n = 0;
|
||||||
for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) {
|
for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) {
|
||||||
n++;
|
n++;
|
||||||
if (gcstate->debug & _PyGC_DEBUG_COLLECTABLE)
|
if (gcstate->debug & _PyGC_DEBUG_UNCOLLECTABLE)
|
||||||
debug_cycle("uncollectable", FROM_GC(gc));
|
debug_cycle("uncollectable", FROM_GC(gc));
|
||||||
}
|
}
|
||||||
stats->uncollectable = n;
|
stats->uncollectable = n;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue