psycopg2 close connection pool
psycopg2 close connection pool I'm developing a Flask API, and I have the following code to have a connection pool using Psycopg2. I wonder should I consider to close the connection pool when the program terminates and how should I do this? @contextmanager def get_cursor(: global connection_pool if not cls.connection_pool: cls.connection_pool = ThreadedConnectionPool(5, 25, dsn=PoolingWrap.generate_conn_string()) con = cls.connection_pool.getconn() try: yield con.cursor(cursor_factory=RealDictCursor) finally: cls.connection_pool.putconn(con) Before going for an answer, I'd like to know if there's a reason you aren't using sqlalchemy, which has ways that help you handle this. – Luis Orduz Jun 26 at 13:59 what server are you using? – Ma...