Skip to content

Conversation

@hyongtao-code
Copy link
Contributor

@hyongtao-codehyongtao-code commented Jan 15, 2026

Fixes an issue where results of expressions executed via _exec_in_closure() were written to sys.stdout instead of the debugger output stream. Adds a regression test to ensure expression results are consistently emitted via pdb.stdout.

Fixes an issue where results of expressions executed via `_exec_in_closure()` were written to `sys.stdout` instead of the debugger output stream. Adds a regression test to ensure expression results are consistently emitted via pdb.stdout. Signed-off-by: Yongtao Huang <[email protected]>
@cocolato
Copy link
Contributor

I think the current test case doesn't actually test the remote debug mode. We need add some tests in test_remote_pdb.py:

classRemotePdbTestCase(unittest.TestCase):
"""Tests for the _PdbServer class."""

@cocolato
Copy link
Contributor

cocolato commented Jan 15, 2026

Let's add some tests like this:

classRemotePdbTestCase(unittest.TestCase): ... deftest_remote_closure_exec(self): self.pdb._exec_in_closure('(lambda: 123)()',{},{}) outputs=self.sockfile.get_output() messages= [o['message'].strip() foroinoutputsif'message'ino] self.assertIn("123", messages)

@hyongtao-code
Copy link
ContributorAuthor

I think the current test case doesn't actually test the remote debug mode.

Thank you very much — I couldn’t agree more with your feedback.

Before that, I spent a long time trying to find an appropriate place for the corresponding test case, and still didn’t get it right. <(_ _)>

@gaogaotiantian
Copy link
Member

The issue is real but it's not because print prints to sys.stdout. It's because remote pdb overrides self.message so we have to use that. sys.stdout is actually replaced with self.stdout in local pdb mode.

@hyongtao-code
Copy link
ContributorAuthor

but it's not because

Totally agree. The actual execution path is:

self.message() → local pdb: print(..., file=self.stdout) → remote pdb: send over the socket

Thank you for helping identify the RCA and clarifying the underlying cause–and–effect relationship.

@gaogaotiantiangaogaotiantian merged commit e66597d into python:mainJan 20, 2026
47 checks passed
@gaogaotiantian
Copy link
Member

Thank you for the contribution!

@miss-islington-app
Copy link

Thanks @hyongtao-code for the PR, and @gaogaotiantian for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 20, 2026
…losure()` (pythonGH-143875) (cherry picked from commit e66597d) Co-authored-by: Yongtao Huang <[email protected]>
@bedevere-app
Copy link

GH-144061 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14 bugs and security fixes label Jan 20, 2026
gaogaotiantian pushed a commit that referenced this pull request Jan 21, 2026
…closure()` (GH-143875) (#144061) gh-143874: Use self.message instead of raw print in `_exec_in_closure()` (GH-143875) (cherry picked from commit e66597d) Co-authored-by: Yongtao Huang <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hyongtao-code@cocolato@gaogaotiantian