Skip to content

Unify the handling of KeyboardInterrupt in new REPLs #129628

Open
@bswck

Description

@bswck

Feature or enhancement

Proposal:

It's a little confusing now.

❯ python -m asyncio
asyncio REPL 3.14.0a4+ (heads/main:7d275611f62, Jan 27 2025, 05:41:56) [GCC 11.4.0] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> raise KeyboardInterrupt

KeyboardInterrupt
>>> 
❯ python
Python 3.14.0a4+ (heads/main:7d275611f62, Jan 27 2025, 05:41:56) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> raise KeyboardInterrupt
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    raise KeyboardInterrupt
KeyboardInterrupt
>>> 

Two options here:

  1. Remove specialcasing of KeyboardInterrupt in the asyncio REPL

    except BaseException:
    if keyboard_interrupted:
    self.write("\nKeyboardInterrupt\n")
    else:
    self.showtraceback()

  2. Specialcase KeyboardInterrupt in the main REPL too, as is in the asyncio REPL

What would you opt for?

Me personally -- 1 (show traceback).

CC @ambv

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-asynciotopic-replRelated to the interactive shelltype-featureA feature request or enhancement

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions