[IMP] Improve the speed - Use the inspect module only if we specify the debug log level

bzr revid: stephane@tinyerp.com-20090119224840-j0yqyaw30tzfrc78
This commit is contained in:
Stephane Wirtel 2009-01-19 23:48:40 +01:00
parent d99f6b27d9
commit a875a71408
1 changed files with 13 additions and 11 deletions

View File

@ -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