3232 creator: either an arbitrary function returning new DB-API 2
3333 connection objects or a DB-API 2 compliant database module
3434 maxusage: the maximum number of reuses of a single connection
35- (the default of 0 or False means unlimited reuse)
35+ (the default of 0 or None means unlimited reuse)
3636 Whenever the limit is reached, the connection will be reset.
3737 setsession: an optional list of SQL commands that may serve to
3838 prepare the session, e.g. ["set datestyle to german", ...].
6363ignored since it would be reopened at the next usage anyway and
6464contrary to the intent of having persistent connections. Instead,
6565the connection will be automatically closed when the thread dies.
66- You can change this behavior be setting persist._closeable to True .
66+ You can change this behavior be setting the closeable parameter .
6767
6868
6969Requirements:
@@ -111,23 +111,28 @@ class PersistentDB:
111111
112112 """
113113
114+ version = __version__
115+
114116 def __init__ (self , creator ,
115- maxusage = 0 , setsession = None , * args , ** kwargs ):
117+ maxusage = 0 , setsession = None , failures = None , closeable = 0 ,
118+ * args , ** kwargs ):
116119 """Set up the persistent DB-API 2 connection generator.
117120
118121 creator: either an arbitrary function returning new DB-API 2
119122 connection objects or a DB-API 2 compliant database module
120123 maxusage: maximum number of reuses of a single connection
121- (number of database operations, 0 or False means unlimited)
124+ (number of database operations, 0 or None means unlimited)
122125 Whenever the limit is reached, the connection will be reset.
123126 setsession: optional list of SQL commands that may serve to prepare
124127 the session, e.g. ["set datestyle to ...", "set time zone ..."]
128+ failures: an optional exception class or a tuple of exception classes
129+ for which the connection failover mechanism shall be applied,
130+ if the default (OperationalError, InternalError) is not adequate
131+ closeable: if this is set to true, then closing connections will
132+ be allowed, but by default this will be silently ignored
125133 args, kwargs: the parameters that shall be passed to the creator
126134 function or the connection constructor of the DB-API 2 module
127135
128- Set the _closeable attribute to True or 1 to allow closing
129- connections. By default, this will be silently ignored.
130-
131136 """
132137 try :
133138 threadsafety = creator .threadsafety
@@ -141,14 +146,17 @@ def __init__(self, creator,
141146 self ._creator = creator
142147 self ._maxusage = maxusage
143148 self ._setsession = setsession
149+ self ._failures = failures
150+ self ._closeable = closeable
144151 self ._args , self ._kwargs = args , kwargs
145- self ._closeable = 0
146152 self .thread = local ()
147153
148154 def steady_connection (self ):
149155 """Get a steady, non-persistent DB-API 2 connection."""
150156 return connect (self ._creator ,
151- self ._maxusage , self ._setsession , * self ._args , ** self ._kwargs )
157+ self ._maxusage , self ._setsession ,
158+ self ._failures , self ._closeable ,
159+ * self ._args , ** self ._kwargs )
152160
153161 def connection (self , shareable = 0 ):
154162 """Get a steady, persistent DB-API 2 connection.
@@ -164,7 +172,6 @@ def connection(self, shareable=0):
164172 con = self .steady_connection ()
165173 if not con .threadsafety ():
166174 raise NotSupportedError ("Database module is not thread-safe." )
167- con ._closeable = self ._closeable
168175 self .thread .connection = con
169176 return con
170177
0 commit comments