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

Allow to retrieve ongoing exception handled by every threads #85607

Closed
jd mannequin opened this issue Jul 29, 2020 · 4 comments
Closed

Allow to retrieve ongoing exception handled by every threads #85607

jd mannequin opened this issue Jul 29, 2020 · 4 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@jd
Copy link
Mannequin

jd mannequin commented Jul 29, 2020

BPO 41435
Nosy @jd, @serhiy-storchaka
PRs
  • bpo-41435: Add sys._current_exceptions() function #21689
  • 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 = <Date 2020-11-02.20:54:45.715>
    created_at = <Date 2020-07-29.15:39:46.446>
    labels = ['interpreter-core', 'type-feature', '3.10']
    title = 'Allow to retrieve ongoing exception handled by every threads'
    updated_at = <Date 2020-11-02.20:54:45.715>
    user = 'https://github.com/jd'

    bugs.python.org fields:

    activity = <Date 2020-11-02.20:54:45.715>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-11-02.20:54:45.715>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2020-07-29.15:39:46.446>
    creator = 'jd'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41435
    keywords = ['patch']
    message_count = 4.0
    messages = ['374575', '374727', '374728', '380223']
    nosy_count = 2.0
    nosy_names = ['jd', 'serhiy.storchaka']
    pr_nums = ['21689']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41435'
    versions = ['Python 3.10']

    @jd
    Copy link
    Mannequin Author

    jd mannequin commented Jul 29, 2020

    In order to do statistical profiling on raised exception, having the ability to poll all the running threads for their currently handled exception would be fantastic.

    There is an exposed function named sys._current_frames() that allows to list the current frame handled by CPython. Having an equivalent for sys._current_exceptions() that would return the content of sys.exc_info() for each running thread would solve the issue.

    @jd jd mannequin added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jul 29, 2020
    @serhiy-storchaka
    Copy link
    Member

    Would not be more useful to add a method to the Thread or frame object to obtain the topmost handled exception? Then you could iterate all threads or frames and obtain exceptions together with other useful information.

    Note also that it omits exceptions in generators and coroutines.

    @jd
    Copy link
    Mannequin Author

    jd mannequin commented Aug 3, 2020

    Adding to the thread object might be a good idea, but it does not work if you ever start threads with the low-level _thread API.
    It's also a different design from the existing sys._current_frames.

    Adding it on top of a frame is interesting though. I think internally it's more linked to the execution stack in a thread than to a frame, though.

    @serhiy-storchaka
    Copy link
    Member

    New changeset 64366fa by Julien Danjou in branch 'master':
    bpo-41435: Add sys._current_exceptions() function (GH-21689)
    64366fa

    @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.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant