Skip to content

Conversation

@hyongtao-code
Copy link
Contributor

@hyongtao-code hyongtao-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 <yongtaoh2022@gmail.com>
@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:

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

@cocolato
Copy link
Contributor

cocolato commented Jan 15, 2026

Let's add some tests like this:

class RemotePdbTestCase(unittest.TestCase):

    ...

    def test_remote_closure_exec(self):
        self.pdb._exec_in_closure('(lambda: 123)()', {}, {})
        outputs = self.sockfile.get_output()
        messages = [o['message'].strip() for o in outputs if 'message' in o]
        self.assertIn("123", messages)

@hyongtao-code
Copy link
Contributor Author

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
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants