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

Updating Py_InspectFlag programmatically #80345

Open
atsuoishimoto mannequin opened this issue Mar 2, 2019 · 1 comment
Open

Updating Py_InspectFlag programmatically #80345

atsuoishimoto mannequin opened this issue Mar 2, 2019 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@atsuoishimoto
Copy link
Mannequin

atsuoishimoto mannequin commented Mar 2, 2019

BPO 36164
Nosy @atsuoishimoto
PRs
  • bpo-36164: add sys.setinspectflag() #12138
  • 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 = None
    closed_at = None
    created_at = <Date 2019-03-02.06:10:23.982>
    labels = ['interpreter-core', 'type-bug']
    title = 'Updating Py_InspectFlag programmatically'
    updated_at = <Date 2019-03-02.06:19:38.296>
    user = 'https://github.com/atsuoishimoto'

    bugs.python.org fields:

    activity = <Date 2019-03-02.06:19:38.296>
    actor = 'python-dev'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2019-03-02.06:10:23.982>
    creator = 'ishimoto'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36164
    keywords = ['patch']
    message_count = 1.0
    messages = ['336993']
    nosy_count = 1.0
    nosy_names = ['ishimoto']
    pr_nums = ['12138']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36164'
    versions = []

    @atsuoishimoto
    Copy link
    Mannequin Author

    atsuoishimoto mannequin commented Mar 2, 2019

    I sometime use a hack to start interactive console after running script.

    .. code-block:: python

       import os

    os.environ['PYTHONINSPECT'] = 'x'
    print("Hello")

    This hack works because PYTHONINSPECT is checked here <https://github.com/python/cpython/blob/master/Modules/main.c#L738>__ when exiting Python.

    However, if the script uses sys.exit() to exit from Python, interactive console doen't apper because unhandled SystemExit exception leads exit() call to kill process, without checking PYTHONINSPECT.

    .. code-block:: python

       import os, sys

    os.environ['PYTHONINSPECT'] = 'x'
    print("Hello")

       sys.exit(1)  # Interactive console will not start

    I think feature to allow updating Py_InspectFlag is useful, and this is a bugs to be fixed. However, setting environment variable to start console is not intuituve.

    So instead of fixing bug, I would like to propose a small function to set Py_InspectFlag to start interactive console after running script.

    .. code-block:: python

        sys.setinteractiveflag(bool)

    Thoughts?

    @atsuoishimoto atsuoishimoto mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 2, 2019
    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants