Skip to content

wait-for-process-in-async-function (ASYNC222)

Derived from the flake8-async linter.

What it does

Checks that async functions do not wait on processes with blocking methods.

Why is this bad?

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

Instead of making a blocking call, use an equivalent asynchronous library or function.

Example

async def foo():
    os.waitpid(0)

Use instead:

def wait_for_process():
    os.waitpid(0)


async def foo():
    await asyncio.loop.run_in_executor(None, wait_for_process)