python-trio / python-trio/trio

Add exception message for easier debugging with `Cancelled`

Open
#3,232 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

debugging design discussion
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

Occasionally we end up digging through logs trying to work out why something was cancelled, and eventually it occurred to me that Trio could help with this. I don't have a complete design proposal, but it would be great to handle each of three cases:

  • a deadline was reached.
  • a sibling task in the Nursery raised an exception, including the name of the erroring task
  • someone called CancelScope.cancel(), including the name of the task in which this was called
    • add a new reason: str | None = None param, so that users can explicitly annotate why they cancelled something

I think we could represent this as a string argument to Cancelled like any other exception message; the only tricky part will be threading it through all the cancellation-delivery machinery 🙂

Comments and design input most welcome, of course!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Cancelled exception, CancelScope.cancel(), and Nursery cancellation paths, then trace the cancellation-delivery machinery; the issue names no files or tests. Done means defining and implementing messages for deadlines, sibling-task failures, and explicit cancellation reasons, including the requested task names and optional reason.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.