classification
Title: Add threading.__excepthook__ similar to sys.__excepthook__
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mariocj89, vstinner
Priority: normal Keywords: patch

Created on 2020-11-10 11:09 by mariocj89, last changed 2020-11-12 17:28 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23218 merged mariocj89, 2020-11-10 11:10
Messages (5)
msg380651 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2020-11-10 11:09
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.
msg380663 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-10 13:45
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 ;-)
msg380666 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2020-11-10 13:53
> 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.
msg380838 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-12 17:27
New changeset 750c5abf43b7b1627ab59ead237bef4c2314d29e by Mario Corchero in branch 'master':
bpo-42308: Add threading.__excepthook__ (GH-23218)
https://github.com/python/cpython/commit/750c5abf43b7b1627ab59ead237bef4c2314d29e
msg380839 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-12 17:28
PR merged, thanks Mario.
History
Date User Action Args
2020-11-12 17:28:17vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg380839

stage: patch review -> resolved
2020-11-12 17:27:51vstinnersetmessages: + msg380838
2020-11-10 13:53:39mariocj89setmessages: + msg380666
2020-11-10 13:45:06vstinnersetmessages: + msg380663
2020-11-10 11:10:41mariocj89setkeywords: + patch
stage: patch review
pull_requests: + pull_request22116
2020-11-10 11:09:01mariocj89create