[Python-checkins] python/dist/src/Lib/logging __init__.py,1.3,1.4
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Thu, 23 Jan 2003 10:29:35 -0800
Update of /cvsroot/python/python/dist/src/Lib/logging
In directory sc8-pr-cvs1:/tmp/cvs-serv30176
Modified Files:
__init__.py
Log Message:
Use lightweight introspection instead of the inspect module hammer.
Removing locking are findCaller() calls as the implementation using
sys._getframe() is thread-safe.
Changes reviewed by Vinay.
Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/logging/__init__.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** __init__.py 15 Nov 2002 23:31:28 -0000 1.3
--- __init__.py 23 Jan 2003 18:29:29 -0000 1.4
***************
*** 20,24 ****
Should work under Python versions >= 1.5.2, except that source line
! information is not available unless 'inspect' is.
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
--- 20,24 ----
Should work under Python versions >= 1.5.2, except that source line
! information is not available unless 'sys._getframe()' is.
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
***************
*** 34,41 ****
except ImportError:
thread = None
- try:
- import inspect
- except ImportError:
- inspect = None
__author__ = "Vinay Sajip <vinay_sajip@red-dove.com>"
--- 34,37 ----
***************
*** 57,60 ****
--- 53,63 ----
_srcfile = os.path.normcase(_srcfile)
+ # _srcfile is only used in conjunction with sys._getframe().
+ # To provide compatibility with older versions of Python, set _srcfile
+ # to None if _getframe() is not available; this value will prevent
+ # findCaller() from being called.
+ if not hasattr(sys, "_getframe"):
+ _srcfile = None
+
#
#_startTime is used as the base when calculating the relative time of events
***************
*** 928,944 ****
file name and line number.
"""
! rv = (None, None)
! frame = inspect.currentframe().f_back
! while frame:
! sfn = inspect.getsourcefile(frame)
! if sfn:
! sfn = os.path.normcase(sfn)
! if sfn != _srcfile:
! #print frame.f_code.co_code
! lineno = inspect.getlineno(frame)
! rv = (sfn, lineno)
! break
! frame = frame.f_back
! return rv
def makeRecord(self, name, level, fn, lno, msg, args, exc_info):
--- 931,942 ----
file name and line number.
"""
! f = sys._getframe(1)
! while 1:
! co = f.f_code
! filename = os.path.normcase(co.co_filename)
! if filename == _srcfile:
! f = f.f_back
! continue
! return filename, f.f_lineno
def makeRecord(self, name, level, fn, lno, msg, args, exc_info):
***************
*** 954,963 ****
all the handlers of this logger to handle the record.
"""
! if inspect and _srcfile:
! _acquireLock()
! try:
! fn, lno = self.findCaller()
! finally:
! _releaseLock()
else:
fn, lno = "<unknown file>", 0
--- 952,957 ----
all the handlers of this logger to handle the record.
"""
! if _srcfile:
! fn, lno = self.findCaller()
else:
fn, lno = "<unknown file>", 0