From 772620925a8e8c173fd1131a80be0f9cc84a6cce Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Thu, 24 Jan 2019 17:38:22 -0500 Subject: Tricky case: Thread switching is getting in the way. --- coverage/sqldata.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'coverage/sqldata.py') diff --git a/coverage/sqldata.py b/coverage/sqldata.py index 9291bddd..fe32dcdc 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -662,7 +662,12 @@ class Sqlite(SimpleReprMixin): # has non-ascii characters in it. Opening a relative file name avoids # a problem if the current directory has non-ascii. filename = os.path.relpath(self.filename) - self.con = sqlite3.connect(filename) + # It can happen that Python switches threads while the tracer writes + # data. The second thread will also try to write to the data, + # effectively causing a nested context. However, given the indempotent + # nature of the tracer operations, sharing a conenction among threads + # is not a problem. + self.con = sqlite3.connect(filename, check_same_thread=False) # This pragma makes writing faster. It disables rollbacks, but we never need them. # PyPy needs the .close() calls here, or sqlite gets twisted up: -- cgit v1.2.1