From 88625f54ebe9e7f9c14f58157ac0427e673a8d29 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 2 Jan 2017 11:12:33 -0500 Subject: When nesting tracers, don't restart on the wrong thread --- coverage/pytracer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'coverage') diff --git a/coverage/pytracer.py b/coverage/pytracer.py index 6cd3ea30..5a1b5d7b 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 "".format( + return "".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): -- cgit v1.2.1