This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add support.catch_threading_exception()
Type: Stage: resolved
Components: Tests Versions: Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2019-07-09 10:26 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14664 merged vstinner, 2019-07-09 10:33
PR 14666 merged miss-islington, 2019-07-09 11:00
Messages (5)
msg347540 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-09 10:26
bpo-1230540 added threading.excepthook() to handle "uncaught exceptions raised by".

I propose to add support.catch_threading_exception(): context manager to ease catching these exceptions.

Attached PR implements it.
msg347543 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-09 10:38
See also bpo-36829: Add

catch_threading_exception() is very close to catch_unraisable_exception().
msg347545 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-09 11:00
New changeset 91b4f7ab7f9a5e0908b91379ee085ae087a76483 by Victor Stinner in branch 'master':
bpo-37526: Add support.catch_threading_exception() (GH-14664)
msg347552 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-09 11:36
New changeset 58f2c7f424fe91ba035918f0f66306af73a37543 by Victor Stinner (Miss Islington (bot)) in branch '3.8':
bpo-37526: Add support.catch_threading_exception() (GH-14664) (GH-14666)
msg347556 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-09 12:37
Maybe the context manager could recreate attributes (set them to None) if the context manager is used wice, but I'm not sure that I don't want to promote to reuse catch_threading_exception().

I didn't check if catch_threading_exception() creates a ref cycle. I guess so. It's likely than storing an exception creates a ref cycle. Anyway, __exit__() removes attributes.
Date User Action Args
2022-04-11 14:59:17adminsetgithub: 81707
2019-07-09 12:37:40vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg347556

stage: patch review -> resolved
2019-07-09 11:36:03vstinnersetmessages: + msg347552
2019-07-09 11:00:34miss-islingtonsetpull_requests: + pull_request14474
2019-07-09 11:00:27vstinnersetmessages: + msg347545
2019-07-09 10:38:04vstinnersetmessages: + msg347543
2019-07-09 10:33:47vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request14472
2019-07-09 10:33:39vstinnersetversions: + Python 3.8
2019-07-09 10:26:30vstinnercreate