Skip to content

Commit e03db73

Browse files
[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 c560df9) Co-authored-by: Sergey Miryanov <[email protected]>
1 parent 5535482 commit e03db73

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/test/test_gc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,18 @@ def run_command(code):
726726
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
727727
b"shutdown; use", stderr)
728728
self.assertNotIn(b"<X 'first'>", stderr)
729+
one_line_re = b"gc: uncollectable <X 0x[0-9A-Fa-f]+>"
730+
expected_re = one_line_re + b"\r?\n" + one_line_re
731+
self.assertNotRegex(stderr, expected_re)
729732
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
730733
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
731734
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
732735
b"shutdown", stderr)
733736
self.assertTrue(
734737
(b"[<X 'first'>, <X 'second'>]" in stderr) or
735738
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
739+
# we expect two lines with uncollectable objects
740+
self.assertRegex(stderr, expected_re)
736741
# With DEBUG_SAVEALL, no additional message should get printed
737742
# (because gc.garbage also contains normally reclaimable cyclic
738743
# references, and its elements get printed at runtime anyway).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a typo that prevented printing of uncollectable objects when the
2+
:const:`gc.DEBUG_UNCOLLECTABLE` mode was set.

Python/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ gc_collect_region(PyThreadState *tstate,
17631763
Py_ssize_t n = 0;
17641764
for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) {
17651765
n++;
1766-
if (gcstate->debug & _PyGC_DEBUG_COLLECTABLE)
1766+
if (gcstate->debug & _PyGC_DEBUG_UNCOLLECTABLE)
17671767
debug_cycle("uncollectable", FROM_GC(gc));
17681768
}
17691769
stats->uncollectable = n;

0 commit comments

Comments
 (0)