diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-03-10 10:30:07 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-03-10 10:30:07 -0400 |
commit | d05b0617fad4d7972c6b8a1c671b4a00c37f1208 (patch) | |
tree | 55bd3840f02bc1d091f3824eafbb92a3c85ed1ef /coverage/collector.py | |
parent | 145329fd982ea56bf1237ca0bea264cd9db9bc7b (diff) | |
download | python-coveragepy-git-d05b0617fad4d7972c6b8a1c671b4a00c37f1208.tar.gz |
Don't issue spurious warnings about the trace function changing. Fixes #164
Diffstat (limited to 'coverage/collector.py')
-rw-r--r-- | coverage/collector.py | 10 |
1 files changed, 7 insertions, 3 deletions
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): |