From d05b0617fad4d7972c6b8a1c671b4a00c37f1208 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 10 Mar 2013 10:30:07 -0400 Subject: Don't issue spurious warnings about the trace function changing. Fixes #164 --- coverage/collector.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'coverage/collector.py') diff --git a/coverage/collector.py b/coverage/collector.py index 0cfd8fff..781a0fa6 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -51,6 +51,7 @@ class PyTracer(object): self.last_exc_back = None self.last_exc_firstlineno = 0 self.arcs = False + self.thread = None def _trace(self, frame, event, arg_unused): """The trace function passed to sys.settrace.""" @@ -118,18 +119,21 @@ 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.""" + if self.thread != threading.currentThread(): + # Called on a different thread than started us: do nothing. + 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): -- cgit v1.2.1