pgtoolkit/pgmanager.py
changeset 23 dc2dbe872fc8
parent 20 73f0d53fef6b
child 24 5664afa530e5
equal deleted inserted replaced
22:680631f35d83 23:dc2dbe872fc8
   187 
   187 
   188     def __del__(self):
   188     def __del__(self):
   189         for conn in tuple(self.conn_known.keys()):
   189         for conn in tuple(self.conn_known.keys()):
   190             self.destroy_conn(conn)
   190             self.destroy_conn(conn)
   191 
   191 
   192     def create_conn(self, name='default', isolation_level=None, keep_alive=True, dsn=None, **kw):
   192     def create_conn(self, name='default', keep_open=1, isolation_level=None, keep_alive=True, dsn=None, **kw):
   193         '''Create named connection.
   193         '''Create named connection.
   194         
   194         
   195         name -- name for connection (default is "default")
   195         name -- name for connection (default is "default")
       
   196         keep_open -- how many connections will be kept open in pool (more connections will still be created,
       
   197                      but they will be closed by put_conn)
   196         isolation_level -- "autocommit", "read_committed", "serializable" or None for driver default
   198         isolation_level -- "autocommit", "read_committed", "serializable" or None for driver default
   197         keep_alive -- set socket to keepalive mode
   199         keep_alive -- set socket to keepalive mode
   198         dsn -- string with connection parameters (dsn means Data Source Name)
   200         dsn -- string with connection parameters (dsn means Data Source Name)
   199         
   201         
   200         Alternative for dsn is keyword args (same names as in dsn).
   202         Alternative for dsn is keyword args (same names as in dsn).
   205 
   207 
   206         if dsn is None:
   208         if dsn is None:
   207             dsn = ' '.join([x[0]+'='+str(x[1]) for x in kw.items() if x[1] is not None])
   209             dsn = ' '.join([x[0]+'='+str(x[1]) for x in kw.items() if x[1] is not None])
   208 
   210 
   209         isolation_level = self._normalize_isolation_level(isolation_level)
   211         isolation_level = self._normalize_isolation_level(isolation_level)
   210         ci = ConnectionInfo(dsn, isolation_level, keep_alive)
   212         ci = ConnectionInfo(dsn, isolation_level, keep_alive, keep_open=keep_open)
   211 
   213 
   212         self.conn_known[name] = ci
   214         self.conn_known[name] = ci
   213         self.conn_pool[name] = []
   215         self.conn_pool[name] = []
   214 
   216 
   215     def close_conn(self, name='default'):
   217     def close_conn(self, name='default'):