Skip to content

Overriding SIGINT doesn't work as expected in the new REPL #120221

Description

@pablogsal

Bug report

In the old REPL, overriding SIGINT and pressing Ctrl-C works as expected:

❯ python
Python 3.11.6 (main, Nov  3 2023, 17:05:41) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal(signal.SIGINT, lambda *x: print("NOOOO"))
<built-in function default_int_handler>
>>> NOOOO
NOOOO

but in the new REPL it doesn't trigger the signal handler:

❯ ./python.exe
Python 3.14.0a0 (heads/more_offsets-dirty:9403c2cf58, Jun  6 2024, 12:10:11) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal(signal.SIGINT, lambda *x: print("NOOOO"))
<built-in function default_int_handler>
>>>
KeyboardInterrupt
>>>

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    on Jun 7, 2024
  2. pablogsal commented on Jun 7, 2024

    @pablogsal
    MemberAuthor
  3. pablogsal commented on Jun 7, 2024

    @pablogsal
    MemberAuthor

    This will be fixed by #120234

  4. vstinner commented on Jun 11, 2024

    @vstinner
    Member

    I noticed the problem when trying to debug Python in gdb. CTRL+C doesn't go into gdb anymore. For now, I'm using a bash alias:

    alias gdb='PYTHON_BASIC_REPL=1 gdb'
    
  5. added 2 commits that reference this issue on Jun 11, 2024
  6. added a commit that references this issue on Jun 11, 2024
  7. added a commit that references this issue on Jun 11, 2024
  8. 1 remaining item

  9. vstinner commented on Jun 12, 2024

    @vstinner
    Member

    Thank you. CTRL+C is gdb stops again the process as expected :)

  10. eryksun commented on Jun 19, 2024

    @eryksun
    Contributor

    This could have been addressed by changing default_keymap in "Lib/_pyepl/reader.py" to map (r"\x03", "interrupt") instead of mapping it to the ctrl_c command. The interrupt command calls os.kill(os.getpid(), signal.SIGINT), which works fine for overriding the SIGINT handler and supporting gdb. That said, the decision to let the terminal send the signal makes it equivalent to how it's currently implemented on Windows, and consistency is a plus.

  11. pablogsal commented on Jun 19, 2024

    @pablogsal
    MemberAuthor

    This could have been addressed by changing default_keymap in "Lib/_pyepl/reader.py" to map (r"\x03", "interrupt") instead of mapping it to the ctrl_c command. The interrupt command calls os.kill(os.getpid(), signal.SIGINT), which works fine for overriding the SIGINT handler and supporting gdb. That said, the decision to let the terminal send the signal makes it equivalent to how it's currently implemented on Windows, and consistency is a plus.

    The problem of that approach is that if you paste a huge buffer and then want to cancel because pasting it's too slow then you need to wait until you get the key press for Ctrl-C to send the signal, which will happen after all the buffer is processed, while using signals directly allows us to cancel almost immediately

  12. added a commit that references this issue on Jun 30, 2024
  13. added a commit that references this issue on Jul 11, 2024
  14. added a commit that references this issue on Jul 17, 2024
  15. reopened this on Sep 6, 2024
  16. ambv commented on Sep 6, 2024

    @ambv
    Contributor

    This broke CTRL-C in the asyncio REPL. Now the interrupt and ctrl_c commands are never executed. I need some more time to investigate what happens on Windows to not break that when fixing Linux/Mac.

  17. added 3 commits that reference this issue on Sep 6, 2024
  18. added a commit that references this issue on Sep 6, 2024
  19. added a commit that references this issue on Sep 6, 2024
  20. ambv commented on Sep 6, 2024

    @ambv
    Contributor

    Fixed by #123799.

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

    3.13only security fixes3.14bugs and security fixesrelease-blockertopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions