##// END OF EJS Templates
util: debugstacktrace, flush before and after writing...
Mads Kiilerich -
r20542:be276526 default
parent child Browse files
Show More
@@ -1989,12 +1989,14 b' class hooks(object):'
1989 1989 for source, hook in self._hooks:
1990 1990 hook(*args)
1991 1991
1992 def debugstacktrace(msg='stacktrace', skip=0, f=sys.stderr):
1992 def debugstacktrace(msg='stacktrace', skip=0, f=sys.stderr, otherf=sys.stdout):
1993 1993 '''Writes a message to f (stderr) with a nicely formatted stacktrace.
1994 Skips the 'skip' last entries.
1994 Skips the 'skip' last entries. By default it will flush stdout first.
1995 1995 It can be used everywhere and do intentionally not require an ui object.
1996 1996 Not be used in production code but very convenient while developing.
1997 1997 '''
1998 if otherf:
1999 otherf.flush()
1998 2000 f.write('%s at:\n' % msg)
1999 2001 entries = [('%s:%s' % (fn, ln), func)
2000 2002 for fn, ln, func, _text in traceback.extract_stack()[:-skip - 1]]
@@ -2002,6 +2004,7 b" def debugstacktrace(msg='stacktrace', sk"
2002 2004 fnmax = max(len(entry[0]) for entry in entries)
2003 2005 for fnln, func in entries:
2004 2006 f.write(' %-*s in %s\n' % (fnmax, fnln, func))
2007 f.flush()
2005 2008
2006 2009 # convenient shortcut
2007 2010 dst = debugstacktrace
General Comments 0
You need to be logged in to leave comments. Login now