8000 gh-134097: Print number of refs & blocks after each statement in new REPL by Eclips4 · Pull Request #134136 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address review comments
  • Loading branch information
ambv committed May 19, 2025
commit cf621d7b6b9dd2c2ff47b3915bf6a4f1ed913f2f
18 changes: 8 additions & 10 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,9 @@ def run_multiline_interactive_console(
more_lines = functools.partial(_more_lines, console)
input_n = 0

if sys._xoptions.get("showrefcount"):
# Were we compiled --with-pydebug?
if hasattr(sys, "gettotalrefcount"):
showrefcount = True
else:
showrefcount = False
else:
showrefcount = False
_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()
Expand Down Expand Up @@ -176,5 +171,8 @@ def maybe_run_command(statement: str) -> bool:
except:
console.showtraceback()
console.resetbuffer()
if showrefcount:
console.write(f"[{sys.gettotalrefcount()} refs, {sys.getallocatedblocks()} blocks]\n")
if show_ref_count:
console.write(
f"[{sys.gettotalrefcount()} refs,"
f" {sys.getallocatedblocks()} blocks]\n"
)
1 change: 1 addition & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ def test_prompt_after_help(self):
@skipUnless(Py_DEBUG, '-X showrefcount requires a Python debug build')
def test_showrefcount(self):
env = os.environ.copy()
env.pop("PYTHON_BASIC_REPL", "")
output, _ = self.run_repl("1\n1+2\nexit()\n", cmdline_args=['-Xshowrefcount'], env=env)
matches = re.findall(r'\[-?\d+ refs, \d+ blocks\]', output)
self.assertEqual(len(matches), 3)
Expand Down
Loading
0