Closed tvone closed 1 month ago
If you use a async-support server framework like fastAPI, you can use something like run_in_threadpool
(supported by starlette in fastAPI).
If you want to be in pure python, you can use run_in_executor
from asyncio.
I am not saying these ways are more faster or performance-better but you can handle the multiple requests at the same time anyway.
If you don't have to do with server-side works, just running in multiple processes can be easier or faster way.
Correct so MongoEngine relies on Pymongo under the hood which is sync-only. MongoEngine and Pymongo are thread-safe so they can work in a multi-threaded application, typically a web application (flask, fastapi, etc). So basically you need to check how to adapt the framework (e.g FastAPi) to run multiple threads / run multiple worker/instances. Closing as this is not a MongoEngine issue
If mongoengine doesn't support async/await, how can python handle multiple api requests at the same time? Can someone help me? Currently my api function is synchronous, it cannot handle multiple get requests at the same time