Skip to content

Commit acd006b

Browse files
ASYNC120 docs (#412)
* ASYNC120 docs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0688d71 commit acd006b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/rules.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ _`ASYNC120` : await-in-except
8686
This will not trigger when :ref:`ASYNC102 <ASYNC102>` does, and if you don't care about losing non-cancelled exceptions you could disable this rule.
8787
This is currently not able to detect asyncio shields.
8888

89+
To handle this correctly, use a shielded cancel scope with a timeout::
90+
91+
try:
92+
await process()
93+
except Exception:
94+
with trio.fail_after(seconds, shield=True):
95+
await cleanup()
96+
raise
97+
98+
The shield prevents cancellation from replacing the current exception, while the timeout ensures cleanup can't block indefinitely. Use :func:`trio.move_on_after` if you want to suppress timeout errors rather than raise them.
99+
89100
_`ASYNC121`: control-flow-in-taskgroup
90101
`return`, `continue`, and `break` inside a :ref:`taskgroup_nursery` can lead to counterintuitive behaviour. Refactor the code to instead cancel the :ref:`cancel_scope` inside the TaskGroup/Nursery and place the statement outside of the TaskGroup/Nursery block. In asyncio a user might expect the statement to have an immediate effect, but it will wait for all tasks to finish before having an effect. See `Trio issue #1493 <https://github.com/python-trio/trio/issues/1493>`_ for further issues specific to trio/anyio.
91102

0 commit comments

Comments
 (0)