classification
Title: Allow to retrieve ongoing exception handled by every threads
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jd, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-07-29 15:39 by jd, last changed 2020-08-03 08:38 by jd.

Pull Requests
URL Status Linked Edit
PR 21689 open jd, 2020-07-30 11:36
Messages (3)
msg374575 - (view) Author: Julien Danjou (jd) * Date: 2020-07-29 15:39
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.
msg374727 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-03 08:10
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.
msg374728 - (view) Author: Julien Danjou (jd) * Date: 2020-08-03 08:38
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.
History
Date User Action Args
2020-08-03 08:38:38jdsetmessages: + msg374728
2020-08-03 08:10:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg374727
2020-07-30 11:36:20jdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20832
2020-07-29 15:39:46jdcreate