René's URL Explorer Experiment


Title: non-readline PyOS_StdioReadline when used with PyOS_InputHook fails is buggy with long input · Issue #103929 · python/cpython · GitHub

Open Graph Title: non-readline PyOS_StdioReadline when used with PyOS_InputHook fails is buggy with long input · Issue #103929 · python/cpython

X Title: non-readline PyOS_StdioReadline when used with PyOS_InputHook fails is buggy with long input · Issue #103929 · python/cpython

Description: Bug report To get this bug you must: not be using the readline based stdin code path must have a GUI toolkit with install as PyOS_InputHook imported try to enter stings into input that are 99 characters or longer. stdin is in line buffer...

Open Graph Description: Bug report To get this bug you must: not be using the readline based stdin code path must have a GUI toolkit with install as PyOS_InputHook imported try to enter stings into input that are 99 chara...

X Description: Bug report To get this bug you must: not be using the readline based stdin code path must have a GUI toolkit with install as PyOS_InputHook imported try to enter stings into input that are 99 chara...

Opengraph URL: https://github.com/python/cpython/issues/103929

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"non-readline PyOS_StdioReadline when used with PyOS_InputHook fails is buggy with long input","articleBody":"# Bug report\r\n\r\nTo get this bug you must:\r\n - not be using the `readline` based stdin code path\r\n - must have a GUI toolkit with install as `PyOS_InputHook` imported\r\n - try to enter stings into `input` that are 99 characters or longer.\r\n - stdin is in line buffered mode\r\n\r\nThe source of the problem is that in \r\n\r\nhttps://github.com/python/cpython/blob/385d8d2b6438c7825006df6106dab41a95332a6a/Parser/myreadline.c#L47-L58\r\n\r\nwhich is called from https://github.com/python/cpython/blob/385d8d2b6438c7825006df6106dab41a95332a6a/Parser/myreadline.c#L304-L322\r\n\r\nWe get the following sequence of events:\r\n\r\n - user calls `input`\r\n - `my_fgets` calls the input hook which blocks until stdin reports ready to read\r\n - `fgets` reads up to the first 99 characters and `my_fgets` returns\r\n - if the input is longer than 99 (including the new line), then the last read character will not be the newline and the calling loop will call `my_fgets` again\r\n - The input hook will be called again, but because there is no new user input (just remaining characters from the last pass) the inputhook blocks.\r\n - if the user hits enter a second time the inputhook will return and `fgets` will read to the original new line\r\n - the second new line will still be in the stdin buffer and will come out immediately the next time `input` is called.\r\n\r\n\r\nPossible flaws in my understanding:\r\n\r\n - I am not clear why the next `input` call immediately rather than getting stuck in the input hook\r\n - entries that are multiples of 100 do not require multiple extra enters\r\n\r\n\r\nThis script demonstrates the problem:\r\n\r\n```python\r\nimport string\r\nimport sys\r\nfrom tkinter import Tk\r\nfrom tkinter import ttk\r\n\r\n\r\ndef run():\r\n    \"\"\"\r\n    This sets up a minimal tk application that has enough functionality\r\n    to verify it is \"live\" and the inputhook is running while waiting for\r\n    user input.\r\n    \"\"\"\r\n    root = Tk()\r\n    frm = ttk.Frame(root, padding=10)\r\n    frm.grid()\r\n    lbl = ttk.Label(frm, text=\"push count = 0\")\r\n    lbl.grid(column=0, row=0)\r\n\r\n    j = 0\r\n\r\n    def set_label():\r\n        nonlocal j\r\n        j += 1\r\n        lbl[\"text\"] = f\"push count = {j}\"\r\n\r\n    ttk.Button(frm, text=\"Push me!\", command=set_label).grid(column=1, row=0)\r\n\r\n    return root, frm\r\n\r\n\r\nrun()\r\n\r\nprint(\"This is a demo of a bug in the non-readline based stdio code\\n\\n\")\r\nprint(f\"The readline module is not loaded: {'readline' in sys.modules=}\")\r\n\r\ntest_string = (string.ascii_lowercase + string.ascii_uppercase) * 2\r\n\r\nprint(\r\n    f\"\"\"\r\nWe are using the test string :\r\n\r\n\\t{test_string}\r\n\r\nas it is easy to eyeball the length (it is 104 characters long in 26\r\ncharacter blocks).\r\n\r\nYou should see a tk window with a button that says \"Push me!\" and a counter.\r\nPushing the button should increment the counter.\r\n\r\nFollow the instructions to demonstrate the bug.\r\n\r\n\r\n\"\"\"\r\n)\r\n\r\nprint(\r\n    f\"\"\"\r\nTo see a case where it works paste\r\n\r\n{test_string[:10]}\r\n\r\ninto the prompt below.  Before hitting return, try pushing\r\nthe button on the UI to verify that the inputhook is running.\r\n\"\"\"\r\n)\r\n\r\na = input(\"paste here >> \")\r\nprint(f\"You pasted {a}\")\r\n\r\n\r\nprint(\r\n    f\"\"\"\r\nTo see it fail past the full string\r\n\r\n{test_string}\r\n\r\ninto the prompt below (you will have to hit enter twice)\r\n\"\"\"\r\n)\r\n\r\na = input(\"paste here >> \")\r\nprint(f\"You pasted {a}\")\r\n\r\nprint(\"There is still a newline in the buffer, this input will be 'skipped'\\n\")\r\na = input(\"you can not input here >> \")\r\nprint(f\"we got an empty string!: {a=!r} (also note no new line in stdout)\")\r\n\r\n\r\nprint(\r\n    f\"\"\"\r\n\r\nyou can now play with it or ctrl-d to exit.\r\n\r\nThe longest string that works is (98 letters + new line):\r\n\r\n{test_string[:98]}\r\n\r\n\"\"\"\r\n)\r\n\r\nwhile True:\r\n    print(\"\\n\")\r\n    a = input(\"test input >> \")\r\n    print(f\"what you entered: {a=}\")\r\n```\r\n\r\nThis needs to be run as `python demo.py` not pasted into a shell because the code paths that rely on `readline` work correctly.  Running as `python -uu demo.py` also works correctly.\r\n\r\n# Your environment\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in -->\r\n\r\n- CPython versions tested on: 3.10.10, 3.11.3, 3.9+\r\n- Operating system and architecture: (arch) linux x86, OSX\r\n\r\nThis was originally reported via https://github.com/matplotlib/matplotlib/issues/25756 where you can see my notes as I sorted this out.\r\n\r\nBased on the code paths I expect this to not be reproducible on Windows.\r\n\r\nI think this bug goes back to at least 717c6f95bebcd4693781e25bae3f7f9900cece07 so I expect all currently supported versions of Python to be affected.\r\n\r\nI will shortly open a PR with a proposed fix.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-103931\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tacaswell","@type":"Person","name":"tacaswell"},"datePublished":"2023-04-27T15:32:33Z","url":"https://github.com/python/cpython/issues/103929"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6c6f267c-70bc-334d-9253-8e131bb636dd
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBB70:1DC474:18F286:20F6CB:6B024A63
html-safe-noncea11dcf5cc6997b28d321f567e3f6a356a0718019f8da16b7d61a1dd4161b8f96
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjcwOjFEQzQ3NDoxOEYyODY6MjBGNkNCOjZCMDI0QTYzIiwidmlzaXRvcl9pZCI6IjU4MzczNTk5NzU4NTY0OTExMDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5bb3980b38b1ab0c9632fd25435c0403ba0aab0e061dbe9db3b1040ab11652ae
hovercard-subject-tagissue:1687096734
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/103929/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e9a95e8173144ec03e6ac90caae2bd8b39ad741a7641c6dedfeda7a6eabaf6e4/python/cpython/issues/103929
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e9a95e8173144ec03e6ac90caae2bd8b39ad741a7641c6dedfeda7a6eabaf6e4/python/cpython/issues/103929
og:image:altBug report To get this bug you must: not be using the readline based stdin code path must have a GUI toolkit with install as PyOS_InputHook imported try to enter stings into input that are 99 chara...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametacaswell
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/103929#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F103929
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F103929
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/103929
Reloadhttps://github.com/python/cpython/issues/103929
Reloadhttps://github.com/python/cpython/issues/103929
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/103929
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/103929
#103931https://github.com/python/cpython/pull/103931
non-readline PyOS_StdioReadline when used with PyOS_InputHook fails is buggy with long inputhttps://github.com/python/cpython/issues/103929#top
#103931https://github.com/python/cpython/pull/103931
3.10 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.10%20(EOL)%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/tacaswell
tacaswellhttps://github.com/tacaswell
on Apr 27, 2023https://github.com/python/cpython/issues/103929#issue-1687096734
cpython/Parser/myreadline.chttps://github.com/python/cpython/blob/385d8d2b6438c7825006df6106dab41a95332a6a/Parser/myreadline.c#L47-L58
385d8d2https://github.com/python/cpython/commit/385d8d2b6438c7825006df6106dab41a95332a6a
cpython/Parser/myreadline.chttps://github.com/python/cpython/blob/385d8d2b6438c7825006df6106dab41a95332a6a/Parser/myreadline.c#L304-L322
385d8d2https://github.com/python/cpython/commit/385d8d2b6438c7825006df6106dab41a95332a6a
matplotlib/matplotlib#25756https://github.com/matplotlib/matplotlib/issues/25756
717c6f9https://github.com/python/cpython/commit/717c6f95bebcd4693781e25bae3f7f9900cece07
GH-103929: handle long input lines with PyOS_InputHook #103931https://github.com/python/cpython/pull/103931
tacaswellhttps://github.com/tacaswell
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Apr 27, 2023https://github.com/python/cpython/issues/103929#event-9116045122
tacaswellhttps://github.com/tacaswell
on Apr 27, 2023https://github.com/python/cpython/issues/103929#event-9116079497
FIX: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/df65f13f3c24b40794704cb13884d66c118ceaaa
https://docs.github.com/articles/closing-issues-via-commit-messages
df65f13https://github.com/tacaswell/cpython/commit/df65f13f3c24b40794704cb13884d66c118ceaaa
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/a63c908c16436789c82088ae84ea0a39e634f26a
pythonGH-103929https://github.com/python/cpython/issues/103929
https://docs.github.com/articles/closing-issues-via-commit-messages
a63c908https://github.com/tacaswell/cpython/commit/a63c908c16436789c82088ae84ea0a39e634f26a
https://github.com/jdtsmith
jdtsmithhttps://github.com/jdtsmith
on Apr 27, 2023https://github.com/python/cpython/issues/103929#issuecomment-1526266516
tacaswellhttps://github.com/tacaswell
on Apr 27, 2023https://github.com/python/cpython/issues/103929#event-9119328112
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/1e6fc5ba7fa7d0e42346ab4761672795171c4d10
pythonGH-103929https://github.com/python/cpython/issues/103929
1e6fc5bhttps://github.com/tacaswell/cpython/commit/1e6fc5ba7fa7d0e42346ab4761672795171c4d10
mdboomhttps://github.com/mdboom
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.10 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.10%20(EOL)%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
on May 2, 2023https://github.com/python/cpython/issues/103929#event-9146817027
tacaswellhttps://github.com/tacaswell
on Jun 30, 2023https://github.com/python/cpython/issues/103929#event-9692339693
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/e3759ab8852f6bcff8711453c17b7caccfecf476
pythonGH-103929https://github.com/python/cpython/issues/103929
e3759abhttps://github.com/tacaswell/cpython/commit/e3759ab8852f6bcff8711453c17b7caccfecf476
tacaswellhttps://github.com/tacaswell
on Oct 17, 2023https://github.com/python/cpython/issues/103929#event-10682501461
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/281588a2ee7d62310d8132db685107692131f559
pythonGH-103929https://github.com/python/cpython/issues/103929
281588ahttps://github.com/tacaswell/cpython/commit/281588a2ee7d62310d8132db685107692131f559
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/e69cd681eb85e3c4d63128820bae54f990bb59e4
pythonGH-103929https://github.com/python/cpython/issues/103929
e69cd68https://github.com/tacaswell/cpython/commit/e69cd681eb85e3c4d63128820bae54f990bb59e4
tacaswellhttps://github.com/tacaswell
on Dec 4, 2023https://github.com/python/cpython/issues/103929#event-11143832010
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/5f76a9549db9ef30a342a6649328c50b18158191
pythonGH-103929https://github.com/python/cpython/issues/103929
5f76a95https://github.com/tacaswell/cpython/commit/5f76a9549db9ef30a342a6649328c50b18158191
tacaswellhttps://github.com/tacaswell
on Dec 4, 2025https://github.com/python/cpython/issues/103929#event-21346655446
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/274c3326d9d57f55d12e1811d287d83d46273ade
pythonGH-103929https://github.com/python/cpython/issues/103929
274c332https://github.com/tacaswell/cpython/commit/274c3326d9d57f55d12e1811d287d83d46273ade
tacaswellhttps://github.com/tacaswell
on Jun 29, 2026https://github.com/python/cpython/issues/103929#event-27335488426
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/9438b7d7e36e2d5a688bb711c168fb193524a3c1
pythonGH-103929https://github.com/python/cpython/issues/103929
9438b7dhttps://github.com/tacaswell/cpython/commit/9438b7d7e36e2d5a688bb711c168fb193524a3c1
tacaswellhttps://github.com/tacaswell
on Oct 6, 2026https://github.com/python/cpython/issues/103929#event-32645527051
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/07d59b5115d1a0d428e3c5ce3cbd75f5caff5230
pythonGH-103929https://github.com/python/cpython/issues/103929
07d59b5https://github.com/tacaswell/cpython/commit/07d59b5115d1a0d428e3c5ce3cbd75f5caff5230
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/a4a2b0c92f06d894f20adf0807f01661454873b3
pythonGH-103929https://github.com/python/cpython/issues/103929
a4a2b0chttps://github.com/tacaswell/cpython/commit/a4a2b0c92f06d894f20adf0807f01661454873b3
tacaswellhttps://github.com/tacaswell
on Oct 29, 2026https://github.com/python/cpython/issues/103929#event-34540211007
pythonGH-103929: handle long input lines with PyOS_InputHookhttps://github.com/tacaswell/cpython/commit/c3a50dccaffd452360ae59362caf7f34201bf1df
pythonGH-103929https://github.com/python/cpython/issues/103929
c3a50dchttps://github.com/tacaswell/cpython/commit/c3a50dccaffd452360ae59362caf7f34201bf1df
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/103929
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/103929
3.10 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.10%20(EOL)%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.12only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.12%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.