zhanymkanov/fastapi-best-practices

Use `run_in_threadpool` or not?

hmbui-noze opened this issue · 2 comments

Thank you again for this useful repo.
I have a question regarding your tip 23. I wonder what the differences between using def function and run_in_threadpool in async function. They works the same way to my knowledge. My use case is that I'm using google_storage_python to download file from GCS but it's a blocking I/O library

@hmbui-noze I can recommend an amazing book about Async programming, the code examples are based on Rust, but the principles can applied to any programming language:
Asynchronous Programming in Rust
Discussion page:
https://www.reddit.com/r/rust/comments/1amlro1/new_rust_book_asynchronous_programming_in_rust_is/

In tip 23, run_in_threadpool is useful, when you can't use def router, i.e. you have other async parts.