MushroomMaula / fastapi_login

FastAPI-Login tries to provide similar functionality as Flask-Login does.
https://pypi.org/project/fastapi-login
MIT License
639 stars 58 forks source link

Make def user callback run in worker thread #92

Closed rafelpermata closed 1 year ago

rafelpermata commented 2 years ago

Hi, if user loader is using sync db connection and the def function, it will run in the main thread and block the main thread from receiving any request. So it the def function should be run in worker thread instead.

MushroomMaula commented 2 years ago

I assume anyio is another package that provides the run_sync function? In that case, I would rather not add a complete package just for the sake of one function. If the same functionality can be achieved with the current dependencies or the standard library, I will gladly merge the changes.

rafelpermata commented 2 years ago

I assume anyio is another package that provides the run_sync function? In that case, I would rather not add a complete package just for the sake of one function. If the same functionality can be achieved with the current dependencies or the standard library, I will gladly merge the changes.

Hi, fastapi is based on anyio, so I think it is no problem to use it https://fastapi.tiangolo.com/async/#write-your-own-async-code

MushroomMaula commented 1 year ago

FastAPI does not seem to explicitly depend on AnyIO see here. I have decided however to add the dependency to ensure that, in the case fastapi decides to stop using AnyIO no issues will occur. Thanks for creating the PR.