Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make def user callback run in worker thread #92

Conversation

rafelpermata
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

rafelpermata commented Sep 18, 2022

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 MushroomMaula changed the base branch from master to development March 27, 2023 11:37
@MushroomMaula
Copy link
Owner

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.

@MushroomMaula MushroomMaula merged commit e224985 into MushroomMaula:development Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants