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

PyOS_InputHook is not called when waiting for input() in Windows #75727

Closed
yhlam mannequin opened this issue Sep 21, 2017 · 12 comments
Closed

PyOS_InputHook is not called when waiting for input() in Windows #75727

yhlam mannequin opened this issue Sep 21, 2017 · 12 comments
Labels
3.7 (EOL) end of life OS-windows type-bug An unexpected behavior, bug, or error

Comments

@yhlam
Copy link
Mannequin

yhlam mannequin commented Sep 21, 2017

BPO 31546
Nosy @pfmoore, @tjguk, @zware, @zooba, @ZackerySpytz, @yhlam, @miss-islington
PRs
  • bpo-31546: fix input hook integration on windows #7978
  • [3.7] bpo-31546: Fix input hook integration (GH-7978) #7990
  • [3.6] bpo-31546: Fix input hook integration (GH-7978) #7991
  • Files
  • test_tk.py: TK test script
  • py35_call_stack.png: Python 3.5 call stack
  • py36_call_stack.png: Python 3.6 call stack
  • 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 2019-07-23.15:44:37.548>
    created_at = <Date 2017-09-21.16:13:02.342>
    labels = ['type-bug', '3.7', 'OS-windows']
    title = 'PyOS_InputHook is not called when waiting for input() in Windows'
    updated_at = <Date 2019-07-23.15:44:37.548>
    user = 'https://github.com/yhlam'

    bugs.python.org fields:

    activity = <Date 2019-07-23.15:44:37.548>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-07-23.15:44:37.548>
    closer = 'steve.dower'
    components = ['Windows']
    creation = <Date 2017-09-21.16:13:02.342>
    creator = 'yhlam'
    dependencies = []
    files = ['47160', '47161', '47162']
    hgrepos = []
    issue_num = 31546
    keywords = ['patch']
    message_count = 12.0
    messages = ['302701', '302702', '302703', '302705', '302707', '304785', '305567', '305568', '320674', '320680', '320681', '348067']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'ZackerySpytz', 'yhlam', 'miss-islington']
    pr_nums = ['7978', '7990', '7991']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31546'
    versions = ['Python 3.6', 'Python 3.7']

    @yhlam
    Copy link
    Mannequin Author

    yhlam mannequin commented Sep 21, 2017

    Since python 3.6, PyOS_InputHook is not called when waiting for IO in Windows.

    This causes issues with GUI framework like tkinter that relys on PyOS_InputHook to handle user interaction.

    I attached a test script. When running the script with python 3.5, the tkinter window will show up properly. But if you run the script with python 3.6, the tkinter window will be frozen.

    I believe the issue is introduced in commit 3929499. In commit 3929499, _PyOS_WindowsConsoleReadline is added as the new Windows implementation of PyOS_StdioReadline. Originally, PyOS_StdioReadline calls my_fgets to read input, and my_fgets will call PyOS_InputHook before the calling the real fgets. However, _PyOS_WindowsConsoleReadline calls ReadConsoleW instead of my_fgets to read input, and PyOS_InputHook is never called.

    The bug is first reported in matplotlib.
    matplotlib/matplotlib#9206 (comment)

    @yhlam yhlam mannequin added 3.7 (EOL) end of life OS-windows type-bug An unexpected behavior, bug, or error labels Sep 21, 2017
    @yhlam
    Copy link
    Mannequin Author

    yhlam mannequin commented Sep 21, 2017

    Attach python 3.5 call stack of the test script

    @yhlam
    Copy link
    Mannequin Author

    yhlam mannequin commented Sep 21, 2017

    Attach python 3.6 call stack of the test script

    @zooba
    Copy link
    Member

    zooba commented Sep 21, 2017

    You're right, we're missing this section of code:

        if (PyOS_InputHook != NULL)
            (void)(PyOS_InputHook)();
    

    Since we just call it and ignore anything it does, it should be safe enough to add it immediately before the ReadConsoleW call (inside the loop).

    @zooba
    Copy link
    Member

    zooba commented Sep 21, 2017

    (Belongs inside Parser/myreadline.c in the _PyOS_WindowsConsoleReadline function)

    @yhlam
    Copy link
    Mannequin Author

    yhlam mannequin commented Oct 23, 2017

    As the fix seems simple, any chance this bug can be fixed in next python 3.6 maintenance release? It is the major roadblock for my application to upgrade to python 3.6. Thanks

    @zooba
    Copy link
    Member

    zooba commented Nov 4, 2017

    The fix is simple, just need someone to do a PR. (I might get to it eventually, but I'm working on other things right now.)

    @zooba
    Copy link
    Member

    zooba commented Nov 4, 2017

    And yes, I think this is fine for 3.6.

    @zooba
    Copy link
    Member

    zooba commented Jun 28, 2018

    New changeset 9b9d58f by Steve Dower (Thomas A Caswell) in branch 'master':
    bpo-31546: Fix input hook integration (GH-7978)
    9b9d58f

    @miss-islington
    Copy link
    Contributor

    New changeset 0ebd1bc by Miss Islington (bot) in branch '3.6':
    bpo-31546: Fix input hook integration (GH-7978)
    0ebd1bc

    @zooba
    Copy link
    Member

    zooba commented Jun 28, 2018

    New changeset 9d92524 by Steve Dower (Miss Islington (bot)) in branch '3.7':
    bpo-31546: Fix input hook integration (GH-7978)
    9d92524

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Jul 17, 2019

    Can this issue be closed? PR 7978 was merged and backported.

    @zooba zooba closed this as completed Jul 23, 2019
    @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
    3.7 (EOL) end of life OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants