1010
1111logger = logging .getLogger ("django.geventpool" )
1212
13- connection_pools = {}
1413connection_pools_lock = Semaphore (value = 1 )
1514
1615
17- class DatabaseWrapperMixin ( object ) :
16+ class DatabaseWrapperMixin :
1817 pool_class = None
1918 creation_class = DatabaseCreation
2019 INTRANS = None
20+ _connection_pools = {}
21+
2122
2223 def __init__ (self , * args , ** kwargs ):
2324 self ._pool = None
@@ -29,11 +30,11 @@ def pool(self):
2930 if self ._pool is not None :
3031 return self ._pool
3132 with connection_pools_lock :
32- if self .alias not in connection_pools :
33- self ._pool = self .pool_class (super (), ** self .get_connection_params (), connect = lambda parent , ** kw : parent . get_new_connection ( conn_params = kw ))
34- connection_pools [self .alias ] = self ._pool
33+ if self .alias not in self . _connection_pools :
34+ self ._pool = self .pool_class (** self .get_connection_params ())
35+ self . _connection_pools [self .alias ] = self ._pool
3536 else :
36- self ._pool = connection_pools [self .alias ]
37+ self ._pool = self . _connection_pools [self .alias ]
3738 return self ._pool
3839
3940 def get_new_connection (self , conn_params : dict ):
@@ -62,7 +63,7 @@ def close(self):
6263 # will occur at every request.
6364 self .connection = None
6465 logger .warning (
65- "psycopg2 error while closing the connection." , exc_info = sys .exc_info ()
66+ "psycopg error while closing the connection." , exc_info = sys .exc_info ()
6667 )
6768 raise
6869 finally :
@@ -74,7 +75,7 @@ def close_if_unusable_or_obsolete(self):
7475
7576 def _close (self ):
7677 if self .connection .closed :
77- self .pool .closeall ()
78+ self .pool .close ()
7879 else :
7980 if self .connection .info .transaction_status == self .INTRANS :
8081 self .connection .rollback ()
@@ -84,8 +85,8 @@ def _close(self):
8485 self .connection = None
8586
8687 def closeall (self ):
87- for pool in connection_pools .values ():
88- pool .closeall ()
88+ for pool in self . _connection_pools .values ():
89+ pool .close ()
8990
9091 def set_clean (self ):
9192 if self .in_atomic_block :
0 commit comments