From 12f4f6232cf2b9bf2475844cdcdb12599bab952c Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Wed, 24 Nov 2010 11:48:53 +0200 Subject: [PATCH] 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 --- bin/sql_db.py | 14 ++++++++++---- 1 file 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