Event loop closing when reusing an AsyncEngine #11507
Unanswered
abhay-apella
asked this question in
Usage Questions
Replies: 1 comment 1 reply
-
I think I understand the issue a bit better, it seems if I run |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am attempting to build a shared singleton object that maintains the connection pool that can shared by my FastAPI webservers worker process thread pool. I created a health check function that executes a trivial query to ensure db connectivity by invoking
async_sessionmaker
and then executing the query and having the session context manager close. The health check function is called via a rest endpoint that is called once every 5s. However, on attempting to run this I frequently get event loop closed errors much like here:#5994
I notice the answer there is that I should dispose the engine every single time as well. However, I don't wish to do that as I want to maintain using a shared connection pool between my webserver threads. Is this a potential bug or am I doing something wrong?
Using:
Code
I build the engine instance as a callable singleton the returns the session maker and engine associated with it.
I define a health check function that is periodically called (once every 5s) that creates a session, executes a simple query and closes.
I've also attempted to refactor the session_maker instance into a per thread call so that only the engine is created per process:
This however still results in:
RuntimeError: Event loop is closed
Beta Was this translation helpful? Give feedback.
All reactions