Commits

jason kirtland  committed b790feb

- Re-raise SystemExit et al in _ConnectionRecord.close
- Little code cleanup- decreased verbosity of string formatting.

  • Participants
  • Parent commits d96d709

Comments (0)

Files changed (1)

File lib/sqlalchemy/pool.py

     def close(self):
         if self.connection is not None:
             if self.__pool._should_log_info:
-                self.__pool.log("Closing connection %s" % repr(self.connection))
+                self.__pool.log("Closing connection %r" % self.connection)
             try:
                 self.connection.close()
+            except (SystemExit, KeyboardInterrupt):
+                raise
             except:
                 if self.__pool._should_log_info:
-                    self.__pool.log("Exception closing connection %s" % repr(self.connection))
-                
+                    self.__pool.log("Exception closing connection %r" %
+                                    self.connection)
 
     def invalidate(self, e=None):
         if self.__pool._should_log_info:
             if e is not None:
-                self.__pool.log("Invalidate connection %s (reason: %s:%s)" % (repr(self.connection), e.__class__.__name__, str(e)))
+                self.__pool.log("Invalidate connection %r (reason: %s:%s)" %
+                                (self.connection, e.__class__.__name__, e))
             else:
-                self.__pool.log("Invalidate connection %s" % repr(self.connection))
+                self.__pool.log("Invalidate connection %r" % self.connection)
         self.__close()
         self.connection = None
 
                     l.connect(self.connection, self)
         elif (self.__pool._recycle > -1 and time.time() - self.starttime > self.__pool._recycle):
             if self.__pool._should_log_info:
-                self.__pool.log("Connection %s exceeded timeout; recycling" % repr(self.connection))
+                self.__pool.log("Connection %r exceeded timeout; recycling" %
+                                self.connection)
             self.__close()
             self.connection = self.__connect()
             self.info.clear()
     def __close(self):
         try:
             if self.__pool._should_log_info:
-                self.__pool.log("Closing connection %s" % (repr(self.connection)))
+                self.__pool.log("Closing connection %r" % self.connection)
             self.connection.close()
         except Exception, e:
             if self.__pool._should_log_info:
-                self.__pool.log("Connection %s threw an error on close: %s" % (repr(self.connection), str(e)))
+                self.__pool.log("Connection %r threw an error on close: %s" %
+                                (self.connection, e))
             if isinstance(e, (SystemExit, KeyboardInterrupt)):
                 raise
 
             self.starttime = time.time()
             connection = self.__pool._creator()
             if self.__pool._should_log_info:
-                self.__pool.log("Created new connection %s" % repr(connection))
+                self.__pool.log("Created new connection %r" % connection)
             return connection
         except Exception, e:
             if self.__pool._should_log_info:
-                self.__pool.log("Error on connect(): %s" % (str(e)))
+                self.__pool.log("Error on connect(): %s" % e)
             raise
 
     properties = property(lambda self: self.info,
     if connection_record is not None:
         connection_record.backref = None
         if pool._should_log_info:
-            pool.log("Connection %s being returned to pool" % repr(connection))
+            pool.log("Connection %r being returned to pool" % connection)
         if pool._on_checkin:
             for l in pool._on_checkin:
                 l.checkin(connection, connection_record)
             self._connection_record = None
             raise
         if self._pool._should_log_info:
-            self._pool.log("Connection %s checked out from pool" % repr(self.connection))
+            self._pool.log("Connection %r checked out from pool" %
+                           self.connection)
 
     _logger = property(lambda self: self._pool.logger)
 
             except exceptions.DisconnectionError, e:
                 if self._pool._should_log_info:
                     self._pool.log(
-                    "Disconnection detected on checkout: %s" % (str(e)))
+                    "Disconnection detected on checkout: %s" % e)
                 self._connection_record.invalidate(e)
                 self.connection = self._connection_record.get_connection()
                 attempts -= 1
         try:
             self.cursor.close()
         except Exception, e:
-            self.__parent._logger.warn("Error closing cursor: " + str(e))
+            self.__parent._logger.warn("Error closing cursor: " + e)
             if isinstance(e, (SystemExit, KeyboardInterrupt)):
                 raise