Wrap inspect.stack in if __debug__

This commit is contained in:
David Straub 2020-11-07 11:00:52 +01:00 committed by Nick Hall
parent fd26b5f066
commit 22c1d79eae
3 changed files with 28 additions and 26 deletions

View File

@ -157,14 +157,15 @@ def wrapper(method):
This 'wrapped' method logs the original function that was called, and
where it was called from.
"""
if __debug__:
class_name = args[0].__class__.__name__
func_name = method.__name__
frame = inspect.currentframe()
c_frame = frame.f_back
c_code = c_frame.f_code
LOG.debug('calling %s.%s()... from file %s, line %s in %s',
class_name, func_name, c_code.co_filename, c_frame.f_lineno,
c_code.co_name)
class_name, func_name, c_code.co_filename,
c_frame.f_lineno, c_code.co_name)
return method(*args, **keywargs)
return wrapped

View File

@ -71,6 +71,7 @@ def make_database(plugin_id):
if mod:
database = getattr(mod, pdata.databaseclass)
db = database()
if __debug__:
import inspect
frame = inspect.currentframe()
c_frame = frame.f_back
@ -79,7 +80,6 @@ def make_database(plugin_id):
"Called from File %s, line %s, in %s",
db.__class__.__name__, hex(id(db)), c_code.co_filename,
c_frame.f_lineno, c_code.co_name)
return db
else:
raise Exception("can't load database backend: '%s'" % plugin_id)

View File

@ -85,14 +85,15 @@ class DbState(Callback):
This replaces tests on DbState.open, DbState.db, DbState.db.is_open()
and DbState.db.db_is_open all of which are deprecated.
"""
if __debug__:
class_name = self.__class__.__name__
func_name = "is_open"
frame = inspect.currentframe()
c_frame = frame.f_back
c_code = c_frame.f_code
_LOG.debug('calling %s.%s()... from file %s, line %s in %s',
class_name, func_name, c_code.co_filename, c_frame.f_lineno,
c_code.co_name)
class_name, func_name, c_code.co_filename,
c_frame.f_lineno, c_code.co_name)
return (self.db is not None) and self.db.is_open()
def change_database(self, database):