summaryrefslogtreecommitdiff
path: root/coverage/collector.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-09-16 21:24:21 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-09-16 21:24:21 -0400
commit5dce0bc12651b339f947c87b9a2f40ccce892416 (patch)
tree07abfd265a33959f1983e0ecb4d81df7fb311a48 /coverage/collector.py
parent58b2eb011cb5036a1654eb731d4cf30f467eda89 (diff)
downloadpython-coveragepy-git-5dce0bc12651b339f947c87b9a2f40ccce892416.tar.gz
The PyTracer can't always be stopped, so give it a flag to stop tracing when that happens. This silences a noisome exception during the test suite.
Diffstat (limited to 'coverage/collector.py')
-rw-r--r--coverage/collector.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index 9a74700d..8ba7d87c 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -52,10 +52,14 @@ class PyTracer(object):
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."""
+ if self.stopped:
+ return
+
if 0:
sys.stderr.write("trace event: %s %r @%d\n" % (
event, frame.f_code.co_filename, frame.f_lineno
@@ -126,8 +130,11 @@ class PyTracer(object):
def stop(self):
"""Stop this Tracer."""
+ self.stopped = True
if self.thread != threading.currentThread():
- # Called on a different thread than started us: do nothing.
+ # 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: