Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE: Fix AttributeError when running code #82183

Open
rhettinger opened this issue Sep 1, 2019 · 7 comments
Open

IDLE: Fix AttributeError when running code #82183

rhettinger opened this issue Sep 1, 2019 · 7 comments
Assignees
Labels
3.9 only security fixes topic-IDLE triaged The issue has been accepted as valid by a triager. type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

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']

    @rhettinger
    Copy link
    Contributor Author

    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'

    @rhettinger rhettinger added 3.8 only security fixes 3.9 only security fixes labels Sep 1, 2019
    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    Member

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

    @miss-islington
    Copy link
    Contributor

    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
    Copy link
    Contributor

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

    @terryjreedy
    Copy link
    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.

    @rhettinger
    Copy link
    Contributor Author

    Thank you for investigating this.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland added the triaged The issue has been accepted as valid by a triager. label Jul 31, 2022
    @terryjreedy terryjreedy changed the title 'ModifiedInterpreter' object has no attribute 'interp' IDLE: Fix AttributeError when running code Aug 6, 2022
    @terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error and removed 3.8 only security fixes labels Aug 6, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes topic-IDLE triaged The issue has been accepted as valid by a triager. type-bug An unexpected behavior, bug, or error
    Projects
    Status: In Progress
    Development

    No branches or pull requests

    4 participants