I actually answered a similar answer:
Python Postgres psycopg2 ThreadedConnectionPool exhausted
Basically, I configure the pool of asynchronous connections with gevent, starting the Threadpool connection through postgres and adding the state of the green connection to postgres.
Thus, basically it creates a predefined pool of connections that you specify (for example, 100), and then request queues using this pool, since one request is returned, a new request is processed. I like this approach better than the regular postgres pool due to the asynchronous nature of the requests and the ease of implementation inside the web structure.
source share