8000 gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode wa… · python/cpython@c560df9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c560df9

Browse files
gh-136517: Print uncollectable objects if DEBUG_UNCOLLECTABLE mode was set (#136518)
1 parent 59acdba commit c560df9

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
@@ -732,13 +732,18 @@ def run_command(code):
732732
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
733733
b"shutdown; use", stderr)
734734
self.assertNotIn(b"<X 'first'>", stderr)
735+
one_line_re = b"gc: uncollectable <X 0x[0-9A-Fa-f]+>"
736+
expected_re = one_line_re + b"\r?\n" + one_line_re
737+
self.assertNotRegex(stderr, expected_re)
735738
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
736739
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
737740
self.assertIn(b"ResourceWarning: gc: 2 uncollectable objects at "
738741
b"shutdown", stderr)
739742
self.assertTrue(
740743
(b"[<X 'first'>, <X 'second'>]" in stderr) or
741744
(b"[<X 'second'>, <X 'first'>]" in stderr), stderr)
745+
# we expect two lines with uncollectable objects
746+
self.assertRegex(stderr, expected_re)
742747
# With DEBUG_SAVEALL, no additional message should get printed
743748
# (because gc.garbage also contains normally reclaimable cyclic
744749
# 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
@@ -1782,7 +1782,7 @@ gc_collect_region(PyThreadState *tstate,
17821782
Py_ssize_t n = 0;
17831783
for (gc = GC_NEXT(&finalizers); gc != &finalizers; gc = GC_NEXT(gc)) {
17841784
n++;
1785-
if (gcstate->debug & _PyGC_DEBUG_COLLECTABLE)
1785+
if (gcstate->debug & _PyGC_DEBUG_UNCOLLECTABLE)
17861786
debug_cycle("uncollectable", FROM_GC(gc));
17871787
}
17881788
stats->uncollectable = n;

0 commit comments

Comments
 (0)
0