summaryrefslogtreecommitdiff
path: root/coverage/ctracer
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2017-10-21 20:29:09 +0000
committerNed Batchelder <nedbat@gmail.com>2017-10-21 20:29:09 +0000
commit5e142b6c029f3a7672ff89a9883895622e8b57dc (patch)
treece0da676d10be369c077b7111787259af2f6f063 /coverage/ctracer
parent9e22cdaf8d1e1b39814d04c9b8badda4c0d4769a (diff)
parent6f79cf1d20452bfd6222410165e13a1b75e1b5bb (diff)
downloadpython-coveragepy-git-5e142b6c029f3a7672ff89a9883895622e8b57dc.tar.gz
Merged in ogrisel/coverage.py/fix-thread-safety (pull request #127)
FIX thread-safe Collector.save_data()
Diffstat (limited to 'coverage/ctracer')
-rw-r--r--coverage/ctracer/tracer.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/coverage/ctracer/tracer.c b/coverage/ctracer/tracer.c
index 625a45a6..0ade7412 100644
--- a/coverage/ctracer/tracer.c
+++ b/coverage/ctracer/tracer.c
@@ -833,6 +833,14 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
return RET_OK;
#endif
+ if (!self->started) {
+ /* If CTracer.stop() has been called from another thread, the tracer
+ is still active in the current thread. Let's deactivate ourselves
+ now. */
+ PyEval_SetTrace(NULL, NULL);
+ return RET_OK;
+ }
+
#if WHAT_LOG || TRACE_LOG
PyObject * ascii = NULL;
#endif
@@ -1027,7 +1035,10 @@ static PyObject *
CTracer_stop(CTracer *self, PyObject *args_unused)
{
if (self->started) {
- PyEval_SetTrace(NULL, NULL);
+ /* Set the started flag only. The actual call to
+ PyEval_SetTrace(NULL, NULL) is delegated to the callback
+ itself to ensure that it called from the right thread.
+ */
self->started = FALSE;
}