diff options
| author | P. Christeas <p_christ@hol.gr> | 2010-11-24 11:48:53 +0200 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2010-11-24 11:48:53 +0200 |
| commit | 12f4f6232cf2b9bf2475844cdcdb12599bab952c (patch) | |
| tree | 0549685b10bfa1943908c4cc01f0f48b6be51536 /bin/sql_db.py | |
| parent | 5d53dcc70079ca3041cc731bac44e9baf9a289f4 (diff) | |
sql_db: only do frame inspection when debugging
This affects the "Cursor not closed explicitly..." message.
The message is at a "warning" level, but the frame inspection added
some expensive overhead to each cursor open. So, avoid that unless we
are at debug mode.
bzr revid: p_christ@hol.gr-20101124094853-0ljr6nebkyya0eui
Diffstat (limited to 'bin/sql_db.py')
| -rw-r--r-- | bin/sql_db.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py index 89f5cb01c27..95d1f7d24be 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -94,7 +94,10 @@ class Cursor(object): self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) self.__closed = False # real initialisation value self.autocommit(False) - self.__caller = frame_codeinfo(currentframe(),2) + if self.sql_log: + self.__caller = frame_codeinfo(currentframe(),2) + else: + self.__caller = False def __del__(self): if not self.__closed: @@ -103,9 +106,12 @@ class Cursor(object): # but the database connection is not put back into the connection # pool, preventing some operation on the database like dropping it. # This can also lead to a server overload. - msg = "Cursor not closed explicitly\n" \ - "Cursor was created at %s:%s" - self.__logger.warn(msg, *self.__caller) + msg = "Cursor not closed explicitly\n" + if self.__caller: + msg += "Cursor was created at %s:%s" % self.__caller + else: + msg += "Please enable sql debugging to trace the caller." + self.__logger.warn(msg) self._close(True) @check |
