Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3 #61819

Closed
Drekin mannequin opened this issue Apr 2, 2013 · 13 comments
Closed

MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3 #61819

Drekin mannequin opened this issue Apr 2, 2013 · 13 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@Drekin
Copy link
Mannequin

Drekin mannequin commented Apr 2, 2013

BPO 17619
Nosy @jcea, @vstinner, @tjguk
Files
  • input-ctrlc.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-04-03.14:05:57.371>
    created_at = <Date 2013-04-02.16:35:51.491>
    labels = ['type-bug']
    title = 'MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3'
    updated_at = <Date 2013-04-03.14:05:57.371>
    user = 'https://bugs.python.org/Drekin'

    bugs.python.org fields:

    activity = <Date 2013-04-03.14:05:57.371>
    actor = 'sbt'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-04-03.14:05:57.371>
    closer = 'sbt'
    components = []
    creation = <Date 2013-04-02.16:35:51.491>
    creator = 'Drekin'
    dependencies = []
    files = ['29666']
    hgrepos = []
    issue_num = 17619
    keywords = ['patch']
    message_count = 13.0
    messages = ['185845', '185873', '185877', '185878', '185899', '185900', '185903', '185906', '185908', '185912', '185918', '185920', '185921']
    nosy_count = 6.0
    nosy_names = ['jcea', 'vstinner', 'tim.golden', 'python-dev', 'sbt', 'Drekin']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17619'
    versions = ['Python 3.3']

    @Drekin
    Copy link
    Mannequin Author

    Drekin mannequin commented Apr 2, 2013

    At least on Windows, input() doesn't raise KeyboardInterrupt when Ctrl-C is hit in Python 3.3 (it does in Python 3.2).

    3.3:
    >>> x = input() # Ctrl-C hit - no exception raised
    >>> x
    NameError
    
    3.2:
    >>> x = input() # Ctrl-C hit
    KeyboardInterrupt

    @Drekin Drekin mannequin added the type-bug An unexpected behavior, bug, or error label Apr 2, 2013
    @jcea
    Copy link
    Member

    jcea commented Apr 3, 2013

    Seems to be windows specific. It works fine on Linux and Solaris.

    @jcea jcea changed the title input() swallows KeyboardInterrupt in Python 3.3 MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3 Apr 3, 2013
    @vstinner
    Copy link
    Member

    vstinner commented Apr 3, 2013

    It may be related to the following commit:

    changeset: 77861:9523c122d6fc
    user: Tim Golden <mail@timgolden.me.uk>
    date: Fri Jun 29 18:39:26 2012 +0100
    files: Parser/myreadline.c
    description:
    Issue bpo-1677: Handle better a race condition between the interactive interpreter and
    the Ctrl-C signal handler on Windows

    @vstinner
    Copy link
    Member

    vstinner commented Apr 3, 2013

    @Drekin: What is your Windows version? How did you start Python?

    @Drekin
    Copy link
    Mannequin Author

    Drekin mannequin commented Apr 3, 2013

    I have Windows Vista Business SP2, 64-bit, (6.0.6002). If I start Python any way (from console, from shortcut, via py.exe or not) the same behavior occurs.

    @Drekin
    Copy link
    Mannequin Author

    Drekin mannequin commented Apr 3, 2013

    However it raises the exception correctly in IDLE.

    The same behavior occured on Windows 7 Home Premium SP1, 64-bit, (6.1.7601).

    @tjguk
    Copy link
    Member

    tjguk commented Apr 3, 2013

    That's because IDLE uses a completely different input loop from the
    console interpreter.

    I'll try to get to this but I'm chock-a-block with other work at the
    moment. If anyone else wants to dig, please do so. if the worst came to
    the worst we could back out my previous changeset but that would still
    leave us with an intermittent race-condition.

    @Drekin
    Copy link
    Mannequin Author

    Drekin mannequin commented Apr 3, 2013

    There is related weird behavior:

    >>> try:
    ...     input()
    ... except KeyboardInterrupt:
    ...     print("exception occured")
    ...
    # Ctrl-C hit
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
    KeyboardInterrupt
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
    KeyboardInterrupt
    >>>

    Seems like handling of Ctrl-C is kind of “out of sync”.

    @sbt
    Copy link
    Mannequin

    sbt mannequin commented Apr 3, 2013

    Maybe this is related to

    http://bugs.python.org/issue13673
    

    which causes PyTraceback_Print() to fail if a signal is received but PyErr_CheckSignals() has not been called.

    Note that wrapping in "try: ... except: raise" makes a traceback appear:

    >>> try: input()
    ... except: raise
    ...
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyboardInterrupt
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyboardInterrupt

    @sbt
    Copy link
    Mannequin

    sbt mannequin commented Apr 3, 2013

    Adding PyErr_CheckSignals() after PyOS_Readline() in builtin_input() seems to fix the problem.

    @tjguk
    Copy link
    Member

    tjguk commented Apr 3, 2013

    +1

    Richard - are you in a position to commit / push?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 3, 2013

    New changeset 241cd716bf5f by Richard Oudkerk in branch '3.3':
    Issue bpo-17619: Make input() check for Ctrl-C correctly on Windows.
    http://hg.python.org/cpython/rev/241cd716bf5f

    @sbt
    Copy link
    Mannequin

    sbt mannequin commented Apr 3, 2013

    Richard - are you in a position to commit / push?

    Done.

    @sbt sbt mannequin closed this as completed Apr 3, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants