This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年03月05日 12:50 by vstinner, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| pyrun_interactive_loop-py3k.patch | vstinner, 2010年03月05日 12:50 | |||
| 8070-use-default-encoding.patch | tlesher, 2012年03月11日 18:31 | review | ||
| 8070-use-default-encoding-2.patch | tlesher, 2012年03月12日 16:56 | review | ||
| Messages (13) | |||
|---|---|---|---|
| msg100471 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年03月05日 12:50 | |
PyRun_InteractiveLoopFlags() only stops if PyRun_InteractiveOneFlags() returns E_EOF. But PyRun_InteractiveOneFlags() if an error occurs:
- sys.stdin has no encoding attribute
- PyArena_New() returns NULL
- PyParser_ASTFromFile() returns NULL
- PyImport_AddModule("__main__") returns NULL
- run_mod() returns NULL
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.
|
|||
| msg100473 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年03月05日 12:55 | |
PyRun_InteractiveLoop() doesn't specify the possible return value. It's maybe because it's always zero and that the error are not handled :-) http://docs.python.org/c-api/veryhigh.html#PyRun_InteractiveLoop PyRun_InteractiveOneFlags() documentation is also wrong: the result can only be: 0 (succes), -1 (exception raised) or E_EOF (=11, end of file). |
|||
| msg102622 - (view) | Author: Tim Lesher (tlesher) * | Date: 2010年04月08日 15:35 | |
I just hit this one myself, and was about to write a bug and patch. On reviewing the patch: 1. This really has the same issue as the original code: it detects one of a few known return values, and will infinitely loop on an unexpected return value. It would be better to explicitly check for 0 (continue), E_EOF (exit normally), and any other result (exit abnormally). 2. I don't think you want to unconditionally call PyErr_Print(), because you don't know for sure that an exception is set. 3. Returning 0 from PyRun_InteractiveLoopFlags() when an error occurs is a behavior change, which makes its documentation incorrect (meaning there should also be a doc patch). But to be honest, I don't think it's correct to return 0 in this case. It seems better to return the actual error code (which also requires a doc patch) If you don't have time to update the patch, let me know and I'll put one together. |
|||
| msg102889 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年04月11日 21:18 | |
I don't have time to write a better patch, please improve mine :-) |
|||
| msg106028 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年05月19日 02:05 | |
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 :-) |
|||
| msg132790 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2011年04月02日 08:29 | |
Issue #11730 has been marked as duplicate. |
|||
| msg132791 - (view) | Author: ysj.ray (ysj.ray) | Date: 2011年04月02日 08:43 | |
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. |
|||
| msg132792 - (view) | Author: ysj.ray (ysj.ray) | Date: 2011年04月02日 08:52 | |
> 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. |
|||
| msg155289 - (view) | Author: Tim Lesher (tlesher) * | Date: 2012年03月10日 03:39 | |
Victor: would you object to ysj.ray's solution? I don't think it was an option when we last looked at this issue. |
|||
| msg155402 - (view) | Author: Tim Lesher (tlesher) * | Date: 2012年03月11日 18:31 | |
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. |
|||
| msg155455 - (view) | Author: Tim Lesher (tlesher) * | Date: 2012年03月12日 16:56 | |
Corrected const warning in previous patch. |
|||
| msg221698 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014年06月27日 17:53 | |
I've failed to reproduce this using latest default on Windows 7, would someone else like to try please. |
|||
| msg305179 - (view) | Author: Xavier de Gaye (xdegaye) * (Python triager) | Date: 2017年10月29日 09:14 | |
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 issue 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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:58 | admin | set | github: 52317 |
| 2017年10月29日 09:14:39 | xdegaye | set | status: open -> closed nosy: + xdegaye messages: + msg305179 resolution: out of date stage: resolved |
| 2014年06月27日 17:53:58 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg221698 versions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3 |
| 2012年03月13日 02:30:15 | eric.araujo | set | versions: + Python 3.3, - Python 2.6, Python 3.1 |
| 2012年03月12日 16:56:22 | tlesher | set | files:
+ 8070-use-default-encoding-2.patch messages: + msg155455 |
| 2012年03月11日 18:31:56 | tlesher | set | files:
+ 8070-use-default-encoding.patch messages: + msg155402 |
| 2012年03月10日 03:39:12 | tlesher | set | messages: + msg155289 |
| 2011年04月02日 08:52:13 | ysj.ray | set | messages: + msg132792 |
| 2011年04月02日 08:43:04 | ysj.ray | set | messages: + msg132791 |
| 2011年04月02日 08:29:09 | vstinner | set | messages: + msg132790 |
| 2010年05月19日 09:20:45 | ysj.ray | set | nosy:
+ ysj.ray |
| 2010年05月19日 02:05:27 | vstinner | set | messages: + msg106028 |
| 2010年04月11日 21:18:04 | vstinner | set | messages: + msg102889 |
| 2010年04月08日 15:35:09 | tlesher | set | nosy:
+ tlesher messages: + msg102622 |
| 2010年03月05日 12:55:32 | vstinner | set | messages: + msg100473 |
| 2010年03月05日 12:50:18 | vstinner | create | |