DebugClients/Python/coverage/debug.py

changeset 5051
3586ebd9fac8
parent 4491
0d8612e24fef
diff -r 04e5dfbd3f3d -r 3586ebd9fac8 DebugClients/Python/coverage/debug.py
--- a/DebugClients/Python/coverage/debug.py	Sat Jul 23 13:33:54 2016 +0200
+++ b/DebugClients/Python/coverage/debug.py	Sun Jul 24 12:01:01 2016 +0200
@@ -7,6 +7,10 @@
 import os
 import sys
 
+from coverage.misc import isolate_module
+
+os = isolate_module(os)
+
 
 # When debugging, it can be helpful to force some options, especially when
 # debugging the configuration mechanisms you usually use to control debugging!
@@ -38,7 +42,7 @@
             msg = "pid %5d: %s" % (os.getpid(), msg)
         self.output.write(msg+"\n")
         if self.should('callers'):
-            dump_stack_frames(self.output)
+            dump_stack_frames(out=self.output)
         self.output.flush()
 
     def write_formatted_info(self, header, info):
@@ -76,7 +80,7 @@
             yield "%*s: %s" % (label_len, label, data)
 
 
-def short_stack():                                          # pragma: debugging
+def short_stack(limit=None):                                # pragma: debugging
     """Return a string summarizing the call stack.
 
     The string is multi-line, with one line per stack frame. Each line shows
@@ -88,15 +92,17 @@
         import_local_file : /Users/ned/coverage/trunk/coverage/backward.py @159
         ...
 
+    `limit` is the number of frames to include, defaulting to all of them.
+
     """
-    stack = inspect.stack()[:0:-1]
+    stack = inspect.stack()[limit:0:-1]
     return "\n".join("%30s : %s @%d" % (t[3], t[1], t[2]) for t in stack)
 
 
-def dump_stack_frames(out=None):                            # pragma: debugging
+def dump_stack_frames(limit=None, out=None):                # pragma: debugging
     """Print a summary of the stack to stdout, or some place else."""
     out = out or sys.stdout
-    out.write(short_stack())
+    out.write(short_stack(limit=limit))
     out.write("\n")
 
 #

eric ide

mercurial