gh-134097: Print number of refs & blocks after each statement in new REPL (gh-134136)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Kirill Podoprigora 2025-05-19 14:30:43 +01:00 committed by GitHub
parent 44b73d3cd4
commit c31547a591
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View file

@ -110,6 +110,10 @@ def run_multiline_interactive_console(
more_lines = functools.partial(_more_lines, console)
input_n = 0
_is_x_showrefcount_set = sys._xoptions.get("showrefcount")
_is_pydebug_build = hasattr(sys, "gettotalrefcount")
show_ref_count = _is_x_showrefcount_set and _is_pydebug_build
def maybe_run_command(statement: str) -> bool:
statement = statement.strip()
if statement in console.locals or statement not in REPL_COMMANDS:
@ -167,3 +171,8 @@ def run_multiline_interactive_console(
except:
console.showtraceback()
console.resetbuffer()
if show_ref_count:
console.write(
f"[{sys.gettotalrefcount()} refs,"
f" {sys.getallocatedblocks()} blocks]\n"
)