| Index: third_party/coverage-3.7.1/coverage/collector.py
|
| diff --git a/third_party/coverage-3.6/coverage/collector.py b/third_party/coverage-3.7.1/coverage/collector.py
|
| similarity index 93%
|
| rename from third_party/coverage-3.6/coverage/collector.py
|
| rename to third_party/coverage-3.7.1/coverage/collector.py
|
| index 96a9661bdd896ac3d821ecde135e6904ed4cac21..8ba7d87cd4e055b2e11efccd487bc7493f58d19d 100644
|
| --- a/third_party/coverage-3.6/coverage/collector.py
|
| +++ b/third_party/coverage-3.7.1/coverage/collector.py
|
| @@ -51,13 +51,19 @@ class PyTracer(object):
|
| self.last_exc_back = None
|
| self.last_exc_firstlineno = 0
|
| self.arcs = False
|
| + self.thread = None
|
| + self.stopped = False
|
|
|
| def _trace(self, frame, event, arg_unused):
|
| """The trace function passed to sys.settrace."""
|
|
|
| - #print("trace event: %s %r @%d" % (
|
| - # event, frame.f_code.co_filename, frame.f_lineno),
|
| - # file=sys.stderr)
|
| + if self.stopped:
|
| + return
|
| +
|
| + if 0:
|
| + sys.stderr.write("trace event: %s %r @%d\n" % (
|
| + event, frame.f_code.co_filename, frame.f_lineno
|
| + ))
|
|
|
| if self.last_exc_back:
|
| if frame == self.last_exc_back:
|
| @@ -73,10 +79,11 @@ class PyTracer(object):
|
| # in this file.
|
| self.data_stack.append((self.cur_file_data, self.last_line))
|
| filename = frame.f_code.co_filename
|
| - tracename = self.should_trace_cache.get(filename)
|
| - if tracename is None:
|
| + if filename not in self.should_trace_cache:
|
| tracename = self.should_trace(filename, frame)
|
| self.should_trace_cache[filename] = tracename
|
| + else:
|
| + tracename = self.should_trace_cache[filename]
|
| #print("called, stack is %d deep, tracename is %r" % (
|
| # len(self.data_stack), tracename))
|
| if tracename:
|
| @@ -117,18 +124,24 @@ class PyTracer(object):
|
| Return a Python function suitable for use with sys.settrace().
|
|
|
| """
|
| + self.thread = threading.currentThread()
|
| sys.settrace(self._trace)
|
| return self._trace
|
|
|
| def stop(self):
|
| """Stop this Tracer."""
|
| + self.stopped = True
|
| + if self.thread != threading.currentThread():
|
| + # Called on a different thread than started us: we can't unhook
|
| + # ourseves, but we've set the flag that we should stop, so we won't
|
| + # do any more tracing.
|
| + return
|
| +
|
| if hasattr(sys, "gettrace") and self.warn:
|
| if sys.gettrace() != self._trace:
|
| msg = "Trace function changed, measurement is likely wrong: %r"
|
| self.warn(msg % (sys.gettrace(),))
|
| - #--debug
|
| - #from coverage.misc import short_stack
|
| - #self.warn(msg % (sys.gettrace()))#, short_stack()))
|
| + #print("Stopping tracer on %s" % threading.current_thread().ident)
|
| sys.settrace(None)
|
|
|
| def get_stats(self):
|
| @@ -161,7 +174,7 @@ class Collector(object):
|
| """Create a collector.
|
|
|
| `should_trace` is a function, taking a filename, and returning a
|
| - canonicalized filename, or False depending on whether the file should
|
| + canonicalized filename, or None depending on whether the file should
|
| be traced or not.
|
|
|
| If `timid` is true, then a slower simpler trace function will be
|
| @@ -205,7 +218,7 @@ class Collector(object):
|
|
|
| # A cache of the results from should_trace, the decision about whether
|
| # to trace execution in a file. A dict of filename to (filename or
|
| - # False).
|
| + # None).
|
| self.should_trace_cache = {}
|
|
|
| # Our active Tracers.
|
|
|