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.

classification
Title: 'ModifiedInterpreter' object has no attribute 'interp'
Type: Stage:
Components: IDLE Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: miss-islington, rhettinger, terry.reedy
Priority: normal Keywords: patch

Created on 2019-09-01 20:08 by rhettinger, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 19203 merged terry.reedy, 2020-03-28 06:18
PR 19207 merged miss-islington, 2020-03-28 16:51
PR 19208 merged miss-islington, 2020-03-28 16:52
Messages (7)
msg350961 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-09-01 20:08
Here's a new traceback I haven't seen before.  I only see these at the end of a session, so I don't know which steps triggered it.

$ python3.8 -m idlelib.idle tmp_pretty_fact_ast.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/idlelib/runscript.py", line 173, in _run_module_event
    interp.runcode(code)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/idlelib/pyshell.py", line 756, in runcode
    self.interp.restart_subprocess()
AttributeError: 'ModifiedInterpreter' object has no attribute 'interp'
msg365193 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-27 21:17
You tried to run editor code and ran into a uncaught idle-process bug, which causes an exit.

pyshell.ModifiedInterpreter.runcode: 760-1
        if self.tkconsole.executing:
            self.interp.restart_subprocess()

The immediate bug is that 'self' *is* the interpreter with the restart_subprocess method, so '.interp' needs to be deleted.  An easy fix in itself.

Puzzle 1 is that I expect that 'executing' should be true whenever Shell is not waiting for a response to '>>>', so that we should be seeing this often.  But it is false when running tkinter code, when sleeping, and when waiting for input(prompt) response, so I don't know how it was ever true for you.

I don't remember ever seeing this exception. I will look at the code that sets and resets it.  Maybe the former is not being called when it should be.

Puzzle 2 is that the subprocess *is* being restarted even with this code being (normally) skipped.  Is it ever needed, even in the (unknown) circumstance that 'executing' is true?  Or would that cause two restarts? This would be a new buglet, though preferable to the current exception exit.  The easy fix may not be enough.

'executing' and other shell booleans are still set as 0 and 1.  I may update these first.
msg365219 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-28 16:51
New changeset 34a49aa3e4d023b5f9e9029f4f1ec68f1a8a8120 by Terry Jan Reedy in branch 'master':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
https://github.com/python/cpython/commit/34a49aa3e4d023b5f9e9029f4f1ec68f1a8a8120
msg365221 - (view) Author: miss-islington (miss-islington) Date: 2020-03-28 17:16
New changeset 8c3ab189ae552401581ecf0b260a96d80dcdae28 by Miss Islington (bot) in branch '3.8':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
https://github.com/python/cpython/commit/8c3ab189ae552401581ecf0b260a96d80dcdae28
msg365222 - (view) Author: miss-islington (miss-islington) Date: 2020-03-28 17:18
New changeset cb758011ce39678fb03e8ac3e924d9084252e1ad by Miss Islington (bot) in branch '3.7':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
https://github.com/python/cpython/commit/cb758011ce39678fb03e8ac3e924d9084252e1ad
msg365343 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-30 19:07
Reproducer: In Shell, run "input('prompt'),  Without giving a response, so that input is left 'executing', switch to editor with valid code, select "Run... Customized", unselect "Restart shell", and select OK.  One will twice see and have to click away a box with
  The Python Shell window is already executing a command;
   please wait until it is finished.
Then the attribute error error appears.

Explanation: Run Module first compiles the editor code to check for syntax errors.  If successful, it 1. restarts the execution process, which *resets executing to False*; 2. runs internal commands with runcommand (called twice) to change working directory, augment sys.path, and possibly change sys.args.  3. runs the compiled user code with runcode.  Thus, the buggy 'executing' clause cannot be triggered.

Run Customized with "Restart shell" unchecked skips the restart and 'executing' may be left True.  If so, runcommand displays the message above and returns False, instead of running the command and returning True.  The runscript code currently ignores the return and calls runcode anyway. 

Guiding principle: The effect of running with run customized with given settings should not depend on whether executable happens to be true when the first runcommand is called.  I verified with time.sleep(15) that a statement can finish executing and executable reset to False while a user is reading the first 'executing' message.  Since setting args has be skipped, the run should be stopped.

Fixes:
1. Only display one 'executing' message.  Either make the 2nd runcommand conditioned on the first succeeding, or combine the two partial duplicate runcommand calls into one.  I will start with the first.


2. Improve the error message.  The user should only run without restart when there is a waiting '>>>' prompt and may need to take action (respond to input(), close a tkinter window, restart a hung execution).  The message should say 'Try again' since execution will not happen.

3. Don't run the users code after the message is given.

4. Fix the AttributeError as specified in my previous message.  For running editor code, runcode will again not ever be called with executing True, and it may be that the clause could be deleted.  But I am not sure what is possible is IDLE is started with both -s (run IDLESTARTUP or PYTHONSTARTUP) and -r file (run file), both of which also call runcode.
msg365345 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-03-30 19:12
Thank you for investigating this.
History
Date User Action Args
2022-04-11 14:59:19adminsetgithub: 82183
2020-03-30 19:12:04rhettingersetmessages: + msg365345
2020-03-30 19:07:58terry.reedysetmessages: + msg365343
stage: patch review ->
2020-03-28 17:18:16miss-islingtonsetmessages: + msg365222
2020-03-28 17:16:09miss-islingtonsetmessages: + msg365221
2020-03-28 16:52:06miss-islingtonsetpull_requests: + pull_request18571
2020-03-28 16:51:59miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request18570
2020-03-28 16:51:28terry.reedysetmessages: + msg365219
2020-03-28 06:18:05terry.reedysetkeywords: + patch
stage: patch review
pull_requests: + pull_request18566
2020-03-27 21:17:46terry.reedysetmessages: + msg365193
2019-09-01 20:08:53rhettingercreate