Skip to content

async-function-with-timeout (ASYNC109)#

Derived from the flake8-async linter.

What it does#

Checks for async functions with a timeout argument.

Why is this bad?#

Rather than implementing asynchronous timeout behavior manually, prefer built-in timeout functionality, such as asyncio.timeout, trio.fail_after, or anyio.move_on_after, among others.

Example#

async def long_running_task(timeout): ...


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

Use instead:

async def long_running_task(): ...


async def main():
    async with asyncio.timeout(2):
        await long_running_task()

References#