diff options
| author | Jason Kirtland <jek@discorporate.us> | 2007-12-19 20:36:37 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2007-12-19 20:36:37 +0000 |
| commit | 501447ada3b1ecb529db927df0b333fb2afb01f5 (patch) | |
| tree | 4a9fdf11c7344281051da28eeecea7a5654cfca1 /lib | |
| parent | b9b0aca7575e347dfd62221c9d515decee4c75f6 (diff) | |
| download | sqlalchemy-501447ada3b1ecb529db927df0b333fb2afb01f5.tar.gz | |
- Re-raise SystemExit et al in _ConnectionRecord.close
- Little code cleanup- decreased verbosity of string formatting.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/pool.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index 7a5c2ef0e..9a40bd307 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -207,20 +207,23 @@ class _ConnectionRecord(object): 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 @@ -233,7 +236,8 @@ class _ConnectionRecord(object): 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() @@ -245,11 +249,12 @@ class _ConnectionRecord(object): 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 @@ -258,11 +263,11 @@ class _ConnectionRecord(object): 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, @@ -285,7 +290,7 @@ def _finalize_fairy(connection, connection_record, pool, ref=None): 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) @@ -306,7 +311,8 @@ class _ConnectionFairy(object): 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) @@ -371,7 +377,7 @@ class _ConnectionFairy(object): 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 @@ -424,7 +430,7 @@ class _CursorFairy(object): 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 |
