From a875a71408e1de8588f82ebd6d6b39bb92f040ed Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Mon, 19 Jan 2009 23:48:40 +0100 Subject: [PATCH] [IMP] Improve the speed - Use the inspect module only if we specify the debug log level bzr revid: stephane@tinyerp.com-20090119224840-j0yqyaw30tzfrc78 --- bin/sql_db.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/bin/sql_db.py b/bin/sql_db.py index 3628213f307..118f8e900dc 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -82,21 +82,23 @@ class Cursor(object): self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor) self.autocommit(False) self.dbname = pool.dbname - - from inspect import stack - self.__caller = tuple(stack()[2][1:3]) + + if tools.config['log_level'] in (netsvc.LOG_DEBUG, netsvc.LOG_DEBUG_RPC): + from inspect import stack + self.__caller = tuple(stack()[2][1:3]) def __del__(self): if hasattr(self, '_obj'): - # Oops. 'self' has not been closed explicitly. - # The cursor will be deleted by the garbage collector, - # 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.__caller + if tools.config['log_level'] in (netsvc.LOG_DEBUG, netsvc.LOG_DEBUG_RPC): + # Oops. 'self' has not been closed explicitly. + # The cursor will be deleted by the garbage collector, + # 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.__caller - log(msg, netsvc.LOG_WARNING) + log(msg, netsvc.LOG_WARNING) self.close() @check