From 2d8b5bb4f36e5624f25b170391fe42d3bfbeb623 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Sat, 11 Aug 2007 23:15:32 +0000 Subject: Added an exception hierarchy shadowing DB-API exc types No more generic SQLErrors wrappers- the shadow type matching the DB-API error is raised. [ticket:706] SQLError is now (also) DBAPIError. DBAPIError and subtype constructors will refuse to wrap a SystemExit or KeyboardInterrupt, returningthe original interrupt exception instead of a new instance. [ticket:689] Added a passthroughs for SE/KI exceptions in a couple except-and-discard situations --- lib/sqlalchemy/pool.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/pool.py') diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index f6965495f..526abe81c 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -241,6 +241,8 @@ class _ConnectionRecord(object): self.connection.close() except Exception, e: self.__pool.log("Connection %s threw an error on close: %s" % (repr(self.connection), str(e))) + if isinstance(e, (SystemExit, KeyboardInterrupt)): + raise def __connect(self): try: @@ -371,6 +373,8 @@ class _ConnectionFairy(object): except Exception, e: if self._connection_record is not None: self._connection_record.invalidate(e=e) + if isinstance(e, (SystemExit, KeyboardInterrupt)): + raise if self._connection_record is not None: if self._pool.echo: self._pool.log("Connection %s being returned to pool" % repr(self.connection)) @@ -394,6 +398,8 @@ class _CursorFairy(object): self.cursor.close() except Exception, e: self.__parent._logger.warn("Error closing cursor: " + str(e)) + if isinstance(e, (SystemExit, KeyboardInterrupt)): + raise def __getattr__(self, key): return getattr(self.cursor, key) @@ -432,8 +438,11 @@ class SingletonThreadPool(Pool): for key, conn in self._conns.items(): try: conn.close() + except (SystemExit, KeyboardInterrupt): + raise except: - # sqlite won't even let you close a conn from a thread that didn't create it + # sqlite won't even let you close a conn from a thread + # that didn't create it pass del self._conns[key] -- cgit v1.2.1