Skip to content

IDLE: Fix AttributeError when running code #82183

Closed

Description

@rhettinger
BPO 38002
Nosy @rhettinger, @terryjreedy, @miss-islington
PRs
  • bpo-38002: Use False/True for IDLE pyshell bools #19203
  • [3.8] bpo-38002: Use False/True for IDLE pyshell bools (GH-19203) #19207
  • [3.7] bpo-38002: Use False/True for IDLE pyshell bools (GH-19203) #19208
  • 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 = None
    created_at = <Date 2019-09-01.20:08:53.818>
    labels = ['expert-IDLE', '3.8', '3.9']
    title = "'ModifiedInterpreter' object has no attribute 'interp'"
    updated_at = <Date 2020-03-30.19:12:04.713>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2020-03-30.19:12:04.713>
    actor = 'rhettinger'
    assignee = 'terry.reedy'
    closed = False
    closed_date = None
    closer = None
    components = ['IDLE']
    creation = <Date 2019-09-01.20:08:53.818>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38002
    keywords = ['patch']
    message_count = 7.0
    messages = ['350961', '365193', '365219', '365221', '365222', '365343', '365345']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'terry.reedy', 'miss-islington']
    pr_nums = ['19203', '19207', '19208']
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue38002'
    versions = ['Python 3.8', 'Python 3.9']

    Linked PRs

    Activity

    1. rhettinger commented on Sep 1, 2019

      @rhettinger
      ContributorAuthor

      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'
    2. terryjreedy commented on Mar 27, 2020

      @terryjreedy
      Member

      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.

    3. terryjreedy commented on Mar 28, 2020

      @terryjreedy
      Member

      New changeset 34a49aa by Terry Jan Reedy in branch 'master':
      bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
      34a49aa

    4. miss-islington commented on Mar 28, 2020

      @miss-islington
      Contributor

      New changeset 8c3ab18 by Miss Islington (bot) in branch '3.8':
      bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
      8c3ab18

    5. miss-islington commented on Mar 28, 2020

      @miss-islington
      Contributor

      New changeset cb75801 by Miss Islington (bot) in branch '3.7':
      bpo-38002: Use False/True for IDLE pyshell bools (GH-19203)
      cb75801

    6. terryjreedy commented on Mar 30, 2020

      @terryjreedy
      Member

      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.

    7. rhettinger commented on Mar 30, 2020

      @rhettinger
      ContributorAuthor

      Thank you for investigating this.

    8. transferred this issue fromon Apr 10, 2022
    9. moved this to In Progress in IDLE Issueson Jul 27, 2022
    10. changed the title [-]'ModifiedInterpreter' object has no attribute 'interp'[/-] [+]IDLE: Fix AttributeError when running code[/+] on Aug 6, 2022
    11. added
      type-bugAn unexpected behavior, bug, or error
      and removed on Aug 6, 2022
    12. nineteendo commented on Jun 2, 2024

      @nineteendo
      Contributor

      Is there still something to do here?

    13. luxedo commented on Jun 18, 2024

      @luxedo

      I just tested the following instructions:

      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.

    14. terryjreedy commented on Jul 1, 2026

      @terryjreedy
      Member

      The attribute error is fixed, but the double display and Shell restart remains. It should display just once and return to the editor.

    15. added 4 commits that reference this issue on Jul 1, 2026
    16. terryjreedy commented on Jul 1, 2026

      @terryjreedy
      Member

      Fixed. Message displayed once and Shell is displayed.

    17. moved this from In Progress to Done in IDLE Issueson Jul 1, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    topic-IDLEtriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions