python-trio / python-trio/trio
Cancelled __aexit__ handlers eat exceptions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
This is what happens when you don't wrap your async context's exit handler in a shielded cancel scope:
… trick question. Nothing happens – the error gets dropped on the floor. Since this is a fairly common mistake (at least IME) I wonder whether we can do something about it. If not (which is what I suspect) we need to document this pitfall more loudly.
import trio
class bar:
async def __aenter__(self):
return self
async def __aexit__(self, *tb):
await trio.sleep(0)
async def foo():
with trio.open_cancel_scope() as s:
async with bar():
s.cancel()
raise RuntimeError("Duh")
trio.run(foo)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in the issue and review Trio's cancellation and async context-manager behavior. Determine whether the dropped exception is intended; if behavior cannot be changed safely, document the shielded cancel-scope requirement and make the expected outcome clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100