diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-02 11:12:33 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-02 11:12:33 -0500 |
commit | 00ebc9756140d03b8ebc0f06b93c4f1183ad19dd (patch) | |
tree | dd9af3a41bc33e9d191da9702da0dbd7713df206 /coverage/pytracer.py | |
parent | 5e8fe18a10c130d82f6df7d1306b142573d88479 (diff) | |
download | python-coveragepy-00ebc9756140d03b8ebc0f06b93c4f1183ad19dd.tar.gz |
When nesting tracers, don't restart on the wrong thread
Diffstat (limited to 'coverage/pytracer.py')
-rw-r--r-- | coverage/pytracer.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/coverage/pytracer.py b/coverage/pytracer.py index 6cd3ea3..5a1b5d7 100644 --- a/coverage/pytracer.py +++ b/coverage/pytracer.py @@ -58,7 +58,7 @@ class PyTracer(object): atexit.register(setattr, self, 'in_atexit', True) def __repr__(self): - return "<PyTracer at 0x{0:0x}: {1} lines in {2} files>".format( + return "<PyTracer at {0}: {1} lines in {2} files>".format( id(self), sum(len(v) for v in self.data.values()), len(self.data), @@ -133,10 +133,18 @@ class PyTracer(object): Return a Python function suitable for use with sys.settrace(). """ + self.stopped = False if self.threading: - self.thread = self.threading.currentThread() + if self.thread is None: + self.thread = self.threading.currentThread() + else: + if self.thread.ident != self.threading.currentThread().ident: + # Re-starting from a different thread!? Don't set the trace + # function, but we are marked as running again, so maybe it + # will be ok? + return self._trace + sys.settrace(self._trace) - self.stopped = False return self._trace def stop(self): |