[Django] #32558: Fail tests when unhandled thread exceptions occur

14 views
Skip to first unread message

Django

unread,
Mar 16, 2021, 2:31:48 PM3/16/21
to django-...@googlegroups.com
#32558: Fail tests when unhandled thread exceptions occur
---------------------------------------------+------------------------
Reporter: Adam Johnson | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
Pair of #32557 and its discussion.

In Python it's possible for a thread to be started, quit with an
exception, and this exception never get seen since the main thread doesn't
call `join()` on the failed thread.

Since Python 3.8 it's possible to detect such a case by installing a hook
at `threading.excepthook`:
https://docs.python.org/3.9/library/threading.html#threading.excepthook

pytest recently added such a hook, alongside the unraisable exception
hook: https://github.com/pytest-dev/pytest/pull/8055

I think we can do similarly here, since an exception in a non-main thread
could indicate a problem with code. This is especially pertinent in the
async world where sync code can be run in threads through `sync_to_async`

--
Ticket URL: <https://code.djangoproject.com/ticket/32558>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 19, 2021, 5:32:57 AM3/19/21
to django-...@googlegroups.com
#32558: Fail tests when unhandled thread exceptions occur
-----------------------------------+------------------------------------

Reporter: Adam Johnson | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: Carlton Gibson, Tom Forbes, Chris Jerdonek (added)
* stage: Unreviewed => Accepted


Comment:

Tentatively accepted. As with #32557, I would like to check this in
practice.

--
Ticket URL: <https://code.djangoproject.com/ticket/32558#comment:1>

Django

unread,
Aug 29, 2026, 11:40:46 AM (12 days ago) Aug 29
to django-...@googlegroups.com
#32558: Fail tests when unhandled thread exceptions occur
-----------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: VIZZARD-X
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by VIZZARD-X):

* owner: nobody => VIZZARD-X
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/32558#comment:2>

Django

unread,
Sep 8, 2026, 2:38:00 AM (2 days ago) Sep 8
to django-...@googlegroups.com
#32558: Fail tests when unhandled thread exceptions occur
-----------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: VIZZARD-X
Type: New feature | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-------------------------------------
Changes (by VIZZARD-X):

* cc: VIZZARD-X (added)
* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/21926 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32558#comment:3>
Reply all
Reply to author
Forward
0 new messages