Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ed94eb

Browse files
committed
Do not print additional shutdown message when gc.DEBUG_SAVEALL is set
1 parent 0055c42 commit 2ed94eb

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/test/test_gc.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ def __del__(self):
482482
x.x = x
483483
x.y = X('second')
484484
del x
485-
if %d:
486-
gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
485+
gc.set_debug(%s)
487486
"""
488487
def run_command(code):
489488
p = subprocess.Popen([sys.executable, "-c", code],
@@ -494,13 +493,19 @@ def run_command(code):
494493
self.assertEqual(stdout.strip(), b"")
495494
return strip_python_stderr(stderr)
496495

497-
stderr = run_command(code % 0)
496+
stderr = run_command(code % "0")
498497
self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
499498
self.assertNotIn(b"[<X 'first'>, <X 'second'>]", stderr)
500499
# With DEBUG_UNCOLLECTABLE, the garbage list gets printed
501-
stderr = run_command(code % 1)
500+
stderr = run_command(code % "gc.DEBUG_UNCOLLECTABLE")
502501
self.assertIn(b"gc: 2 uncollectable objects at shutdown", stderr)
503502
self.assertIn(b"[<X 'first'>, <X 'second'>]", stderr)
503+
# With DEBUG_SAVEALL, no additional message should get printed
504+
# (because gc.garbage also contains normally reclaimable cyclic
505+
# references, and its elements get printed at runtime anyway).
506+
stderr = run_command(code % "gc.DEBUG_SAVEALL")
507+
self.assertNotIn(b"uncollectable objects at shutdown", stderr)
508+
504509

505510
class GCTogglingTests(unittest.TestCase):
506511
def setUp(self):

Modules/gcmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,8 @@ PyGC_Collect(void)
13661366
void
13671367
_PyGC_Fini(void)
13681368
{
1369-
if (garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
1369+
if (!(debug & DEBUG_SAVEALL)
1370+
&& garbage != NULL && PyList_GET_SIZE(garbage) > 0) {
13701371
PySys_WriteStderr(
13711372
"gc: "
13721373
"%" PY_FORMAT_SIZE_T "d uncollectable objects at shutdown:\n",

0 commit comments

Comments
 (0)