Closed virajkanwade closed 4 months ago
Hey @virajkanwade thanks for the suggestion. We will work on this in a few weeks from now.
@rishabhpoddar PR #502
@virajkanwade I think you should use the FastAPI's startup hook and call the async version of the create_or_update_tenant
. It's not recommended to run sync variant in the ASGI environment.
@app.on_event("startup")
async def on_startup():
await create_or_update_tenant(...)
@sattvikc
@app.on_event("startup")
is deprecated, but I was able to get it to work with lifespan
.
Regards
https://github.com/supertokens/supertokens-python/blob/master/supertokens_python/async_to_sync_wrapper.py
I want to call
create_or_update_tenant
after init but before the app starts.The standard way to run a FastAPI application is
or
syncio functions try to run
loop.run_until_complete(co)
which results in loop already running error.There is provision to enable
nest_asyncio
, but it only works withasyncio
loops.uvicorn
by default usesuvloop
which is not compatible withnest_asyncio
.One workaround is to tell
uvicorn
to useasyncio
This takes almost 25% performance hit.
Two potential solutions:
sync
wrapper; Ifuvloop
and running, use the hack below.