Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-131878: Handle top level exceptions in new pyrepl and prevent of closing it#131910
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
gh-131878: Handle top level exceptions in new pyrepl and prevent of closing it#131910
Uh oh!
There was an error while loading.Please reload this page.
Conversation
AFAICT, the swallowed exceptions are already suppressed when executing the statements. When would this ps1=getattr(sys,"ps1",">>> ")ps2=getattr(sys,"ps2","... ")try:statement=multiline_input(more_lines,ps1,ps2)exceptEOFError:breakifmaybe_run_command(statement):continueinput_name=f"<python-input-{input_n}>"more=console.push(_strip_final_indent(statement),filename=input_name,_symbol="single")# type: ignore[call-arg]assertnotmoreinput_n+=1 And in this case, I think it's preferrable to make the REPL exit as it's probably in an unrecoverable state at this point. |
I came from thishttps://github.com/python/cpython/blob/main/Lib/_pyrepl/base_eventqueue.py#L108-L114. We swallow UnicodeError exception. And this is a reason whygh-131878 asserted in another point. And if we caught UnicodeError here it give us much more information. But here we don't have any "tools" to properly say about exception. And going up to stack I "found" an appropriate place in the simple_interact loop. OTOH I may be wrong, and we should not do this. |
I think the issue is that we did not properly handled the inputs there. Or that the assertion where it crashes is incorrect. I didn't look in detail but I don't know if#131901 is the correct approach (ISTM that we cannot send long unicode strings but we can do it as bytes? and that we can do it for unicode strings with a single unicode code point, whether it's strings or bytes?) Nevertheless, when there is a crash like that, I think it's better than we use a debugger instead. At this point of the REPL execution, its state may or may not necessarily be recoverable (I'm actually surprised that we're not aborting because we're out of memory but I guess it's to allow debuggers?) |
As long it affects only Windows so I changed only windows code path. And for both cases (if input has one or more unicode code path) input "char" encoded to bytes and sent to eventqueue. For one-byte unicode string it is a small pessimization. For original issue - we have input == "ñ". If we send it as-is - it sends as str and ord("ñ") == 241. And we just append it to But if we encode it as bytes then we get two bytes - b'\xc3\xb1', also append them (via extend) to buf and decode will be happy. |
Uh oh!
There was an error while loading.Please reload this page.
99a0d7e
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@sergey-miryanov for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry,@sergey-miryanov and@ambv, I could not cleanly backport this to
|
… prevent of closing it (pythonGH-131910)(cherry picked from commit99a0d7e)Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
GH-133445 is a backport of this pull request to the3.13 branch. |
@ambv Thanks! |
Working ongh-131878 I saw a code paths that swallows exceptions. I propose not to swallow them and bubble it up to main input loop and handle there.