Opened 4 years ago

Last modified 4 years ago

#32558 new New feature

Fail tests when unhandled thread exceptions occur

Reported by: Adam Johnson Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Carlton Gibson, Tom Forbes, Chris Jerdonek Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:How to create a pull request

Description

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

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Cc: Carlton Gibson Tom Forbes Chris Jerdonek added
Triage Stage: UnreviewedAccepted

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

Note: See TracTickets for help on using tickets.
Back to Top