You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IDLE: Fix AttributeError when running code #82183
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:
assignee='https://github.com/terryjreedy'closed_at=Nonecreated_at=<Date2019-09-01.20:08:53.818>labels= ['expert-IDLE', '3.8', '3.9']
title="'ModifiedInterpreter' object has no attribute 'interp'"updated_at=<Date2020-03-30.19:12:04.713>user='https://github.com/rhettinger'
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__returnself.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 runcodeself.interp.restart_subprocess()
AttributeError: 'ModifiedInterpreter' object has no attribute 'interp'
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.
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:
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.
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.
Don't run the users code after the message is given.
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.
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.
I got two windows with the message The Python Shell window is already executing a command but no AttributeError in the terminal. Maybe this is fixed already.
Activity
rhettinger commentedon Sep 1, 2019
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.
terryjreedy commentedon Mar 27, 2020
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.
terryjreedy commentedon Mar 28, 2020
New changeset 34a49aa by Terry Jan Reedy in branch 'master':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
34a49aa
miss-islington commentedon Mar 28, 2020
New changeset 8c3ab18 by Miss Islington (bot) in branch '3.8':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
8c3ab18
miss-islington commentedon Mar 28, 2020
New changeset cb75801 by Miss Islington (bot) in branch '3.7':
bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
cb75801
terryjreedy commentedon Mar 30, 2020
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
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:
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.
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.
Don't run the users code after the message is given.
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.
rhettinger commentedon Mar 30, 2020
Thank you for investigating this.
[-]'ModifiedInterpreter' object has no attribute 'interp'[/-][+]IDLE: Fix AttributeError when running code[/+]nineteendo commentedon Jun 2, 2024
Is there still something to do here?
luxedo commentedon Jun 18, 2024
I just tested the following instructions:
I got two windows with the message The Python Shell window is already executing a command but no
AttributeErrorin the terminal. Maybe this is fixed already.terryjreedy commentedon Jul 1, 2026
The attribute error is fixed, but the double display and Shell restart remains. It should display just once and return to the editor.
gh-82183: Do not restart the busy IDLE shell when running without resâĶ
[3.13] gh-82183: Do not restart the busy IDLE shell when running withâĶ
[3.14] gh-82183: Do not restart the busy IDLE shell when running withâĶ
[3.15] gh-82183: Do not restart the busy IDLE shell when running withâĶ
terryjreedy commentedon Jul 1, 2026
Fixed. Message displayed once and Shell is displayed.