blocking-path-method-in-async-function (ASYNC240)
Preview (since 0.13.2) · Related issues · View source
Derived from the flake8-async linter.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks that async functions do not call blocking os.path or pathlib.Path
methods.
Why is this bad?
Calling some os.path or pathlib.Path methods in an async function will block
the entire event loop, preventing it from executing other tasks while waiting
for the operation. This negates the benefits of asynchronous programming.
Instead, use the methods' async equivalents from trio.Path or anyio.Path.
Example
Use instead:
Non-blocking methods are OK to use: