Skip to content

blocking-sleep-in-async-function (ASYNC251)#

Derived from the flake8-async linter.

What it does#

Checks that async functions do not call time.sleep.

Why is this bad?#

Blocking an async function via a time.sleep call will block the entire event loop, preventing it from executing other tasks while waiting for the time.sleep, negating the benefits of asynchronous programming.

Instead of time.sleep, use asyncio.sleep.

Example#

async def fetch():
    time.sleep(1)

Use instead:

async def fetch():
    await asyncio.sleep(1)