Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-134644: handle exceptions set inPyOS_Readline
#134645
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
The builtin input calls `PyOS_Readline` but seems to assume it does not setexceptions: if the call fails it checks signals and runs handlers if any arepending, which will cause an assertion failure if an exception has already beenset.Fix this by only checking signals if an exception has not already been set.
Since this is an internal bug fix, for a mostly a theoretical bug, that probably isn't noticeable without assertions enabled, I don't think it needs a news entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The general idea makes sense to me. Would you mind adding a test case?
if (!PyErr_Occurred()) | ||
PyErr_CheckSignals(); | ||
if (!PyErr_Occurred()) | ||
PyErr_SetNone(PyExc_KeyboardInterrupt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't likeif
clauses that have the same condition right next to each other. Let's refactor to something like this:
if (!PyErr_Occurred()) | |
PyErr_CheckSignals(); | |
if (!PyErr_Occurred()) | |
PyErr_SetNone(PyExc_KeyboardInterrupt); | |
if (!PyErr_Occurred()) { | |
if (PyErr_CheckSignals()==0) { | |
PyErr_SetNone(PyExc_KeyboardInterrupt); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, it looks a little goofy. I'm happy to take your version, but looking at it again, what about:
if (!PyErr_Occurred()&& !PyErr_CheckSignals()) {PyErr_SetNone(PyExc_KeyboardInterrupt);}
Oops, missed this comment. We do need a blurb entry here, since this is indeed user-facing. Some people (cough cough, Gentoo users) do compile Python in release mode with assertions enabled, so there is a chance of this happening in production. I'd suggest something like "Fix assertion failure when |
Sure: I didn't initially because I can't figure out how to write a test that fails with the current version: interrupting the I don't really see any reliable way to achieve that with the signal handling code at present. The reproducer just spams One thing we could consider is adding an assertion check that no exception has been set right at the top of In testing this all seems to work: the new test case crashes before the fix, works after the fix, and the rest of the test suite runs without any problems. I am hesitant about it though, given how wide an impact this would potentially have.
Fair enough, will add! |
Uh oh!
There was an error while loading.Please reload this page.
The builtin input calls
PyOS_Readline
but seems to assume it does not set exceptions: if the call fails it checks signals and runs handlers if any are pending, which will cause an assertion failure if an exception has already been set.Fix this by only checking signals if an exception has not already been set.
PyOS_Readline
#134644