Skip to content

New REPL crash (and terminal display issues) after a breakpoint and by sending Ctrl + D input #129614

Open

Description

@Viicos

Bug report

Bug description:

In a really specific scenario, the terminal can go crazy and becomes unresponsive:

bug.mp4

Steps to reproduce:

  • Create an issue.py file, with a breakpoint set (echo 'breakpoint()' > issue.py).
  • Run issue.py in interactive mode: python -i issue.py
  • Press C to continue when hitting the breakpoint.
  • Start typing something, e.g. help(
  • Input Ctrl + D, as if you wanted to exit the terminal. Nothing happens (as it should).
  • Input Ctrl + C, as if you wanted to clear the line.

If no breakpoint was hit before, this works as expected:

>>> help(  # hit Ctrl + D then Ctrl + C
KeyboardInterrupt

Note trying to reproduce on Python 3.12, the following happens:

--Return--
> /home/victorien/ws/pydantic/issue.py(1)<module>()->None
-> breakpoint()
(Pdb) c
>>> help(  # hit Ctrl + D then Ctrl + C
Program interrupted. (Use 'cont' to resume).
--Return--
> /home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/pdb.py(271)sigint_handler()->None
-> self.set_trace(frame)

Traceback (most recent call last):
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/pdb.py", line 271, in sigint_handler
    self.set_trace(frame)
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/bdb.py", line 94, in trace_dispatch
    return self.dispatch_return(frame, arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/bdb.py", line 153, in dispatch_return
    self.user_return(frame, arg)
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/pdb.py", line 362, in user_return
    self.interaction(frame, None)
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/pdb.py", line 428, in interaction
    self._cmdloop()
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/pdb.py", line 390, in _cmdloop
    self.cmdloop()
  File "/home/victorien/.local/share/uv/python/cpython-3.12.7-linux-x86_64-gnu/lib/python3.12/cmd.py", line 126, in cmdloop
    line = input(self.prompt)
           ^^^^^^^^^^^^^^^^^^
RuntimeError: can't re-enter readline
>>> 

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Feb 3, 2025
  2. ZeroIntensity commented on Feb 4, 2025

    @ZeroIntensity
    Member
  3. gaogaotiantian commented on Feb 4, 2025

    @gaogaotiantian
    Member

    Is Ctrl+C a reasonable way to clear the line? pdb sets up a signal handler for SIGINT (aka Ctrl+C) so users can stop the program with Ctrl+C. I think it conflicts with whatever REPL does. You probably can reproduce this with any code that sets up signal.signal(signal.SIGINT, some_function).

    So my question would be - is this even a bug? If the user code sets up a handler for SIGINT which conflicts with the current REPL, whose fault it is?

    If we consider this a bug, is it a bug for REPL or pdb? Should REPL behave normal when SIGINT is set (to anything arbitrary), or pdb should not do something that REPL dislikes, even though the user can do the exact same thing?

    I mean we can alleviate this by asking pdb to reset the sigint handler in inline mode - but that's actually a behavioral change. It is kind of reasonable, but not backward compatible.

    I'm not an expert on REPL and we need the expertise in that area.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions