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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite loop in PyRun_InteractiveLoopFlags() if PyRun_InteractiveOneFlags() raises an error #52317
Comments
PyRun_InteractiveLoopFlags() only stops if PyRun_InteractiveOneFlags() returns E_EOF. But PyRun_InteractiveOneFlags() if an error occurs:
You can reproduce the error by adding the followg line to the end of Lib/site.py: sys.stdin = object() Attached patch is for py3k, but the bug does also exist in trunk. |
PyRun_InteractiveLoop() doesn't specify the possible return value. It's maybe because it's always zero and that the error are not handled :-) PyRun_InteractiveOneFlags() documentation is also wrong: the result can only be: 0 (succes), -1 (exception raised) or E_EOF (=11, end of file). |
I just hit this one myself, and was about to write a bug and patch. On reviewing the patch:
If you don't have time to update the patch, let me know and I'll put one together. |
I don't have time to write a better patch, please improve mine :-) |
tlesher> If you don't have time to update the patch, let me know and I'll put one together. I would be happy if you write a new patch :-) |
Issue bpo-11730 has been marked as duplicate. |
I'd prefer not exit program but try to use Py_FileSystemDefaultEncoding as enc when sys.stdin is invalid. On most cases, setting sys.stdin to some other invalid value does means the program could not continue running. |
Sorry, it should be: On most cases, setting sys.stdin to some other invalid value does not mean the program could not continue running. |
Victor: would you object to ysj.ray's solution? I don't think it was an option when we last looked at this issue. |
Updated patch: use Py_FileSystemDefaultEncoding (if possible) when sys.stdin is (or becomes) invalid; if none, then fails without entering infinite loop. Docs for PyRun_InteractiveLoopFlags have been updated. |
Corrected const warning in previous patch. |
I've failed to reproduce this using latest default on Windows 7, would someone else like to try please. |
The infinite loop may occur if one of the functions called by PyRun_InteractiveOneObject() returns persistently -1. This may be the case when there is no more memory and is handled by bpo-30696. It is not possible anymore to reproduce the infinite loop reported in the initial post. See how the 'enc' parameter of PyParser_ASTFromFileObject() is NULL in the following gdb session: $ gdb -q python -q
Reading symbols from python...done.
(gdb) run
Starting program: /path_to/src/python/master/python
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Python 3.7.0a2+ (heads/master:bdf4298ae2, Oct 29 2017, 09:44:50)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>
Program received signal SIGINT, Interrupt.
0x00007ffff719daa7 in select () from /usr/lib/libc.so.6
(gdb) break PyParser_ASTFromFileObject
Breakpoint 1 at 0x5555555b38d1: file Python/pythonrun.c, line 1181.
(gdb) continue
Continuing.
sys.stdin = None Breakpoint 1, PyParser_ASTFromFileObject (fp=fp@entry=0x7ffff7461860 <_IO_2_1_stdin_>,
filename=filename@entry='<stdin>', enc=enc@entry=0x0, start=start@entry=256,
ps1=ps1@entry=0x7ffff6e7b220 ">>> ", ps2=ps2@entry=0x7ffff6e7beb8 "... ",
flags=0x7fffffffe338, errcode=0x7fffffffe244, arena=0x7ffff6eb2160) at Python/pythonrun.c:1181
1181 {
(gdb) continue
Continuing.
>>> print(chr(0xe9))
é
Breakpoint 1, PyParser_ASTFromFileObject (fp=fp@entry=0x7ffff7461860 <_IO_2_1_stdin_>,
filename=filename@entry='<stdin>', enc=enc@entry=0x0, start=start@entry=256,
ps1=ps1@entry=0x7ffff6e7b220 ">>> ", ps2=ps2@entry=0x7ffff6e7beb8 "... ",
flags=0x7fffffffe338, errcode=0x7fffffffe244, arena=0x7ffff6eb2160) at Python/pythonrun.c:1181
1181 {
(gdb) continue
Continuing.
>>> Closing as out of date. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: