classification
Title: infinite loop in PyRun_InteractiveLoopFlags()
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner, xdegaye
Priority: normal Keywords: patch

Created on 2017-06-18 10:33 by xdegaye, last changed 2017-11-13 12:40 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
infinite_loop.patch xdegaye, 2017-06-18 10:33
Pull Requests
URL Status Linked Edit
PR 4160 merged xdegaye, 2017-10-28 20:23
PR 4379 merged xdegaye, 2017-11-12 16:08
Messages (9)
msg296267 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-06-18 10:33
To reproduce the problem, apply the nomemory_allocator.patch from issue 30695 and run the following two statements that must be interrupted with ^C:
$  ./python -q
>>> import _testcapi
>>> _testcapi.set_nomemory_allocator()
sys.excepthook is missing
^Cpython: Objects/call.c:785: PyEval_CallObjectWithKeywords: Assertion `!PyErr_Occurred()' failed.
Aborted (core dumped)

The attached patch fixes this problem.
No PR for the moment: this patch and nomemory_allocator.patch are needed to demonstrate other issues.
msg296322 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-06-19 12:29
The patch is far too simplistic. With this patch an exception kills the interactive loop, for example:

$ ./python -q
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
$
msg296324 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-06-19 12:48
See also my old issue #8070 opened 7 years ago :-)
msg306118 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-11-12 15:50
New changeset e0582a37c8d1776a2fd4968e9216f3a05f780276 by xdegaye in branch 'master':
bpo-30696: Fix the REPL looping endlessly when no memory (GH-4160)
https://github.com/python/cpython/commit/e0582a37c8d1776a2fd4968e9216f3a05f780276
msg306120 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-11-12 16:33
New changeset ea5b545e38b3fec7ff29276b5cd59dec583ebf34 by xdegaye in branch '3.6':
[3.6] bpo-30696: Fix the REPL looping endlessly when no memory (GH-4160). (#4379)
https://github.com/python/cpython/commit/ea5b545e38b3fec7ff29276b5cd59dec583ebf34
msg306151 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-13 11:04
Thanks for fixing this very old bug!

What about Python 2.7?
msg306152 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-11-13 11:55
> What about Python 2.7?

_testcapi.set_nomemory() does not exist on Pyhton 2.7 so the changes cannot be tested. Applying the changes to PyRun_InteractiveLoopFlags() in 2.7 looks rather straightforward but there are too many differences in PyRun_InteractiveOneFlags() between 2.7 and 3.7.
msg306153 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2017-11-13 11:59
Also the existing test coverage of these functions in all the Python versions is very weak.
msg306155 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-13 12:40
Ok, I understand, thanks for the explanation.
History
Date User Action Args
2017-11-13 12:40:12vstinnersetmessages: + msg306155
2017-11-13 11:59:21xdegayesetmessages: + msg306153
2017-11-13 11:55:53xdegayesetmessages: + msg306152
2017-11-13 11:04:49vstinnersetmessages: + msg306151
2017-11-12 16:33:59xdegayesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-11-12 16:33:18xdegayesetmessages: + msg306120
2017-11-12 16:08:25xdegayesetpull_requests: + pull_request4327
2017-11-12 15:50:52xdegayesetmessages: + msg306118
2017-10-28 20:32:22xdegayesetversions: - Python 3.5
2017-10-28 20:23:10xdegayesetstage: patch review
pull_requests: + pull_request4129
2017-06-25 09:10:33xdegayesetpull_requests: - pull_request2416
2017-06-23 20:31:48xdegayesetpull_requests: + pull_request2416
2017-06-23 15:59:34xdegayesetpull_requests: - pull_request2407
2017-06-23 15:51:11xdegayesetpull_requests: + pull_request2407
2017-06-19 12:48:55vstinnersetmessages: + msg296324
2017-06-19 12:29:28xdegayesetmessages: + msg296322
2017-06-18 13:53:56xdegayesetversions: + Python 3.5, Python 3.6
2017-06-18 10:33:04xdegayecreate