Title: Builtin input does not always correctly handle errors from `PyOS_Readline` · Issue #134644 · python/cpython · GitHub
Open Graph Title: Builtin input does not always correctly handle errors from `PyOS_Readline` · Issue #134644 · python/cpython
X Title: Builtin input does not always correctly handle errors from `PyOS_Readline` · Issue #134644 · python/cpython
Description: Assertion failure sending SIGINT while calling input import os, signal, threading send = threading.Event() def interrupter(): while True: send.wait() os.kill(os.getpid(), signal.SIGINT) threading.Thread(target=interrupter).start() send.s...
Open Graph Description: Assertion failure sending SIGINT while calling input import os, signal, threading send = threading.Event() def interrupter(): while True: send.wait() os.kill(os.getpid(), signal.SIGINT) threading.T...
X Description: Assertion failure sending SIGINT while calling input import os, signal, threading send = threading.Event() def interrupter(): while True: send.wait() os.kill(os.getpid(), signal.SIGINT) threading.T...
Opengraph URL: https://github.com/python/cpython/issues/134644
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Builtin input does not always correctly handle errors from `PyOS_Readline`","articleBody":"### Assertion failure sending `SIGINT` while calling `input`\n```python\nimport os, signal, threading\n\nsend = threading.Event()\n\ndef interrupter():\n while True:\n send.wait()\n os.kill(os.getpid(), signal.SIGINT)\n\nthreading.Thread(target=interrupter).start()\n\nsend.set()\nwhile True:\n try:\n input(\"\u003e\")\n except KeyboardInterrupt:\n pass\n```\n\nNote, this is a modified version of the example code in #112585.\n\nPython (tested `v3.12.10`, `v3.13.3`, `v3.14.0b1`, and current `HEAD`), built with assertions enabled:\n```\n~/src/cpython/ $ ./python crash.py\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003epython: Objects/call.c:342: _PyObject_Call: Assertion `!_PyErr_Occurred(tstate)' failed.\nAborted (core dumped)\n```\n\nIIUC the issue is `builtin_input_impl` in `Python/bltinmodule.c` calls `PyOS_Readline` but assumes it cannot set an exception:\n```\n s = PyOS_Readline(stdin, stdout, promptstr);\n if (s == NULL) {\n PyErr_CheckSignals();\n if (!PyErr_Occurred())\n PyErr_SetNone(PyExc_KeyboardInterrupt);\n```\n\nIf `PyOS_Readline` sets an exception (e.g. as in this case by running an interrupt signal handler itself), as opposed to being interrupted by a signal and returning `NULL` _without_ setting the exception, and another signal with a handler is pending when `PyErr_CheckSignals()` is called, the handler will be called with the prior exception already set, and hence the assertion fails.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-134645\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/duaneg","@type":"Person","name":"duaneg"},"datePublished":"2025-05-25T04:31:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/134644/cpython/issues/134644"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:673fcbe2-1972-1395-fc4e-c858b8ec0e8f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A864:29681E:471A989:63512A9:6A54EE5E |
| html-safe-nonce | 7e3053d2fe9c7292b0860597204d8c1a2ff10c96f9b707d2c2ac7a3925cb4ddc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODY0OjI5NjgxRTo0NzFBOTg5OjYzNTEyQTk6NkE1NEVFNUUiLCJ2aXNpdG9yX2lkIjoiOTAwNzUxMjI4NjYyNjM3NzMxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 579fa3db04eed819c433198c3aa7cdcf31967da8399015b04f9195ea7c972ead |
| hovercard-subject-tag | issue:3089033544 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/134644/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d03db472494139b7e80e97bb0788959505d51f9d92c43b8d033a463a1ecf2bb7/python/cpython/issues/134644 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d03db472494139b7e80e97bb0788959505d51f9d92c43b8d033a463a1ecf2bb7/python/cpython/issues/134644 |
| og:image:alt | Assertion failure sending SIGINT while calling input import os, signal, threading send = threading.Event() def interrupter(): while True: send.wait() os.kill(os.getpid(), signal.SIGINT) threading.T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | duaneg |
| hostname | github.com |
| expected-hostname | github.com |
| None | eae2aab99907699a22d2c8449aa683ca74454fca87211b98f7c7b722086b2839 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bb1b4ffdc07c66de20ad344214f55df0aa364bd3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width