Skip to content

trio-async-function-with-timeout (TRIO109)#

Derived from the flake8-trio linter.

What it does#

Checks for async functions with a timeout argument.

Why is this bad?#

Rather than implementing asynchronous timeout behavior manually, prefer trio's built-in timeout functionality, available as trio.fail_after, trio.move_on_after, trio.fail_at, and trio.move_on_at.

Known problems#

To avoid false positives, this rule is only enabled if trio is imported in the module.


async def func():
    await long_running_task(timeout=2)

Use instead:

async def func():
    with trio.fail_after(2):
        await long_running_task()