This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyOS_InputHook is not called when waiting for input() in Windows
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, miss-islington, paul.moore, steve.dower, tim.golden, yhlam, zach.ware
Priority: normal Keywords: patch

Created on 2017-09-21 16:13 by yhlam, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_tk.py yhlam, 2017-09-21 16:13 TK test script
py35_call_stack.png yhlam, 2017-09-21 16:15 Python 3.5 call stack
py36_call_stack.png yhlam, 2017-09-21 16:16 Python 3.6 call stack
Pull Requests
URL Status Linked Edit
PR 7978 merged tcaswell, 2018-06-27 21:06
PR 7990 merged miss-islington, 2018-06-28 16:31
PR 7991 merged miss-islington, 2018-06-28 16:31
Messages (12)
msg302701 - (view) Author: Lam Yuen Hei (yhlam) Date: 2017-09-21 16:13
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.
https://github.com/matplotlib/matplotlib/issues/9206#issuecomment-331192016
msg302702 - (view) Author: Lam Yuen Hei (yhlam) Date: 2017-09-21 16:15
Attach python 3.5 call stack of the test script
msg302703 - (view) Author: Lam Yuen Hei (yhlam) Date: 2017-09-21 16:16
Attach python 3.6 call stack of the test script
msg302705 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-09-21 16:25
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).
msg302707 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-09-21 16:26
(Belongs inside Parser/myreadline.c in the _PyOS_WindowsConsoleReadline function)
msg304785 - (view) Author: Lam Yuen Hei (yhlam) Date: 2017-10-23 09:22
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
msg305567 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-11-04 21:40
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.)
msg305568 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-11-04 21:41
And yes, I think this is fine for 3.6.
msg320674 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-06-28 16:29
New changeset 9b9d58f0d88b338eb8d2ae0da5cd91d60d1b0e39 by Steve Dower (Thomas A Caswell) in branch 'master':
bpo-31546: Fix input hook integration (GH-7978)
https://github.com/python/cpython/commit/9b9d58f0d88b338eb8d2ae0da5cd91d60d1b0e39
msg320680 - (view) Author: miss-islington (miss-islington) Date: 2018-06-28 17:47
New changeset 0ebd1bc94a941a5044e26de946c1100d652dfe46 by Miss Islington (bot) in branch '3.6':
bpo-31546: Fix input hook integration (GH-7978)
https://github.com/python/cpython/commit/0ebd1bc94a941a5044e26de946c1100d652dfe46
msg320681 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-06-28 17:48
New changeset 9d92524c11def666a78ff57a9603a9ad6142418a by Steve Dower (Miss Islington (bot)) in branch '3.7':
bpo-31546: Fix input hook integration (GH-7978)
https://github.com/python/cpython/commit/9d92524c11def666a78ff57a9603a9ad6142418a
msg348067 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2019-07-17 15:08
Can this issue be closed? PR 7978 was merged and backported.
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75727
2019-07-23 15:44:37steve.dowersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-07-17 15:08:52ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg348067
2018-06-28 17:48:39steve.dowersetmessages: + msg320681
2018-06-28 17:47:56miss-islingtonsetnosy: + miss-islington
messages: + msg320680
2018-06-28 16:31:55miss-islingtonsetpull_requests: + pull_request7602
2018-06-28 16:31:04miss-islingtonsetpull_requests: + pull_request7601
2018-06-28 16:29:53steve.dowersetmessages: + msg320674
2018-06-27 21:06:47tcaswellsetkeywords: + patch
stage: patch review
pull_requests: + pull_request7589
2017-11-04 21:41:03steve.dowersetmessages: + msg305568
2017-11-04 21:40:52steve.dowersetmessages: + msg305567
2017-10-23 09:22:17yhlamsetmessages: + msg304785
2017-09-21 16:26:05steve.dowersetmessages: + msg302707
2017-09-21 16:25:35steve.dowersetmessages: + msg302705
2017-09-21 16:16:11yhlamsetfiles: + py36_call_stack.png

messages: + msg302703
2017-09-21 16:15:37yhlamsetfiles: + py35_call_stack.png

messages: + msg302702
2017-09-21 16:13:02yhlamcreate