python-trio / python-trio/trio

Enable inspection of `fail_at`/`fail_after` attributes

Open
#3,090 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

After #3010 we will have the following functionality:

my_move_on_at = move_on_at(5)
assert my_move_on_at.deadline == 5
my_move_on_after = move_on_after(5)
assert my_move_on_after.deadline == 5

# but these return Generator[CancelScope], so you can't inspect/modify the objects
my_fail_at = fail_at(5)
assert my_fail_at.deadline == 5 # AttributeError
my_fail_after = fail_after(5)
assert my_fail_after.deadline == 5 # AttributeError

Since separating initialization & entry has been weird previously the current demand might be low for this functionality, but it might become more common.
The two ways I see of fixing this are:

  1. Add a wrapper class that defines __exit__ to raise TooSlowError if cancelled_caught, but otherwise passes __getattr__ and __setattr__ onto CancelScope
  2. Add a fail=True parameter to CancelScope that makes it raise TooSlowError upon being cancelled.

Split out from https://github.com/python-trio/trio/pull/3010#issuecomment-2352619529

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 by reading the changes proposed in #3010 and the entry points for fail_at, fail_after, and CancelScope. Compare the wrapper and CancelScope approaches, then verify that fail_at and fail_after expose an inspectable deadline while retaining their TooSlowError behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.