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 should print exit message or status if one is provided #81139

Closed
random832 mannequin opened this issue May 18, 2019 · 5 comments
Closed

IDLE should print exit message or status if one is provided #81139

random832 mannequin opened this issue May 18, 2019 · 5 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@random832
Copy link
Mannequin

random832 mannequin commented May 18, 2019

BPO 36958
Nosy @terryjreedy, @miss-islington
PRs
  • bpo-36958: In IDLE, print exit message #13435
  • [3.7] bpo-36958: In IDLE, print exit message (GH-13435) #13437
  • Files
  • run.py.patch
  • 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 = <Date 2019-05-20.07:18:14.009>
    created_at = <Date 2019-05-18.19:38:04.536>
    labels = ['3.8', 'expert-IDLE', 'type-bug', '3.7']
    title = 'IDLE should print exit message or status if one is provided'
    updated_at = <Date 2019-05-20.07:18:14.008>
    user = 'https://bugs.python.org/Random832'

    bugs.python.org fields:

    activity = <Date 2019-05-20.07:18:14.008>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2019-05-20.07:18:14.009>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2019-05-18.19:38:04.536>
    creator = 'Random832'
    dependencies = []
    files = ['48335']
    hgrepos = []
    issue_num = 36958
    keywords = ['patch']
    message_count = 5.0
    messages = ['342809', '342823', '342886', '342889', '342890']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'Random832', 'miss-islington']
    pr_nums = ['13435', '13437']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36958'
    versions = ['Python 3.7', 'Python 3.8']

    @random832
    Copy link
    Mannequin Author

    random832 mannequin commented May 18, 2019

    IDLE currently just returns to the interactive prompt when a script exits, even if SystemExit has arguments. This can be confusing to new users if they are using sys.exit to print a message.

    @random832 random832 mannequin added the 3.7 (EOL) end of life label May 18, 2019
    @random832 random832 mannequin assigned terryjreedy May 18, 2019
    @random832 random832 mannequin added the topic-IDLE label May 18, 2019
    @terryjreedy
    Copy link
    Member

    https://docs.python.org/3/library/exceptions.html#SystemExit says: skip traceback, convert default None to 0, print any other non-int and convert to 1, and pass unprinted int to C exit().

    I agree that IDLE should also print non-ints. The IDLE doc should mention its non-exit behavior.

    [https://docs.python.org/3/library/sys.html#sys.exit adds more about int return codes and that exit() only exits the process in the main thread. Neither is relevant here.]

    I believe the relevant code is the following, from run.Executive.runcode:

            except SystemExit:
                # Scripts that raise SystemExit should just
                # return to the interactive prompt
                pass
            except:
                self.usr_exc_info = sys.exc_info()
                if quitting:
                    exit()
                # even print a user code SystemExit exception, continue
                print_exception()
                jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
                if jit:
                    self.rpchandler.interp.open_remote_stack_viewer()

    The bare except clause, including the comment, is from 2003. The 'except SystemExit' clause was added 2013 June 11 in bpo-18196, a follow-up of comments in bpo-5492. The obsoleted comment should have been deleted. The behavior suppressed was always printing traceback + message. What should have been retained was printing non-int messages, but I don't think that either Roger or I were aware of that behavior.

    One could argue that SystemExit in user code should trigger an exit from the user execution process, which would trigger a Shell Restart. This would be closer to the standard behavior. But it does not hurt, and may be better, to keep the process and let the user trigger a restart when wanted. In the case that inspired bpo-18196, the SystemExit came from site.py, not user code, and definitely should not cause a restart.

    I will try something like the following:

            except SystemExit as e:
                ob = e.args[0]
                if not isinstance(ob, (type(None), int)):
                    print('SystemExit: ' + str(ob), file=sys.stderr)

    Since the message will be followed by a normal prompt rather than an exit, I want to 'enhance' the message with the prefix and error color.

    @terryjreedy terryjreedy added 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels May 18, 2019
    @terryjreedy
    Copy link
    Member

    New changeset 6d965b3 by Terry Jan Reedy in branch 'master':
    bpo-36958: In IDLE, print exit message (GH-13435)
    6d965b3

    @miss-islington
    Copy link
    Contributor

    New changeset 2d94d4f by Miss Islington (bot) in branch '3.7':
    bpo-36958: In IDLE, print exit message (GH-13435)
    2d94d4f

    @terryjreedy
    Copy link
    Member

    Thanks for the report.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes topic-IDLE type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants