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

Add threading.__excepthook__ similar to sys.__excepthook__ #86474

Closed
mariocj89 mannequin opened this issue Nov 10, 2020 · 5 comments
Closed

Add threading.__excepthook__ similar to sys.__excepthook__ #86474

mariocj89 mannequin opened this issue Nov 10, 2020 · 5 comments
Labels
3.10 stdlib

Comments

@mariocj89
Copy link
Mannequin

@mariocj89 mariocj89 mannequin commented Nov 10, 2020

BPO 42308
Nosy @vstinner, @mariocj89
PRs
  • #23218
  • 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-12.17:28:17.661>
    created_at = <Date 2020-11-10.11:09:01.522>
    labels = ['library', '3.10']
    title = 'Add threading.__excepthook__ similar to sys.__excepthook__'
    updated_at = <Date 2020-11-12.17:28:17.660>
    user = 'https://github.com/mariocj89'

    bugs.python.org fields:

    activity = <Date 2020-11-12.17:28:17.660>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-11-12.17:28:17.661>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2020-11-10.11:09:01.522>
    creator = 'mariocj89'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42308
    keywords = ['patch']
    message_count = 5.0
    messages = ['380651', '380663', '380666', '380838', '380839']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'mariocj89']
    pr_nums = ['23218']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42308'
    versions = ['Python 3.10']

    @mariocj89
    Copy link
    Mannequin Author

    @mariocj89 mariocj89 mannequin commented Nov 10, 2020

    The sys module contains __excepthook__ to recover sys.excepthook if necessary. The same is not present in the threading module, even if threading.excepthook is exposed.

    @mariocj89 mariocj89 mannequin added 3.10 stdlib labels Nov 10, 2020
    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 10, 2020

    Can't you do that in your own hook? For example:

    orig_hook = threading.excepthook
    threading.excepthook = myhook
    
    def myhook(args):
       try:
          ...
       except:
          print("too bad!")
          orig_hook(args)

    I found one interesting usage of sys.__excepthook__ in code.InteractiveInterpreter:

            if sys.excepthook is sys.__excepthook__:
                lines = traceback.format_exception_only(type, value)
                self.write(''.join(lines))
            else:
                # If someone has set sys.excepthook, we let that take precedence
                # over self.write
                sys.excepthook(type, value, tb)

    So it seems like sys.__excepthook__ is useful ;-)

    @mariocj89
    Copy link
    Mannequin Author

    @mariocj89 mariocj89 mannequin commented Nov 10, 2020

    I found one interesting usage of sys.__excepthook__ in code.InteractiveInterpreter:

    That is exactly what I wished this was there for hehe. We are installing a custom version of excepthook and wanted to check if the user had changed it.

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 12, 2020

    New changeset 750c5ab by Mario Corchero in branch 'master':
    bpo-42308: Add threading.__excepthook__ (GH-23218)
    750c5ab

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 12, 2020

    PR merged, thanks Mario.

    @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 stdlib
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant