diff options
author | Stephan Richter <stephan.richter@gmail.com> | 2019-01-26 09:34:02 -0500 |
---|---|---|
committer | Stephan Richter <stephan.richter@gmail.com> | 2019-01-26 09:34:02 -0500 |
commit | dcd36748c5bf7693b058e3042107e294a49f2712 (patch) | |
tree | 7ca1148cbf4461d62d06c4a2344f1839714466b6 /coverage | |
parent | 6b117e558f5f902090bb6addeb091135cb8b1749 (diff) | |
download | python-coveragepy-git-dcd36748c5bf7693b058e3042107e294a49f2712.tar.gz |
Make thread code Py2 compatible.
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/sqldata.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/coverage/sqldata.py b/coverage/sqldata.py index 67e9da01..24e5d6b8 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -16,14 +16,19 @@ import itertools import os import sqlite3 import sys -import threading +from coverage import env from coverage.backward import iitems from coverage.data import filename_suffix from coverage.debug import NoDebugging, SimpleReprMixin from coverage.files import PathAliases from coverage.misc import CoverageException, file_be_gone +if env.PY2: + from thread import get_ident as get_thread_id +else: + from threading import get_ident as get_thread_id + # Schema versions: # 1: Released in 5.0a2 @@ -115,8 +120,8 @@ class CoverageSqliteData(SimpleReprMixin): def _create_db(self): if self._debug.should('dataio'): self._debug.write("Creating data file {!r}".format(self.filename)) - self._dbs[threading.get_ident()] = Sqlite(self.filename, self._debug) - with self._dbs[threading.get_ident()] as db: + self._dbs[get_thread_id()] = Sqlite(self.filename, self._debug) + with self._dbs[get_thread_id()] as db: for stmt in SCHEMA.split(';'): stmt = " ".join(stmt.strip().split()) if stmt: @@ -130,8 +135,8 @@ class CoverageSqliteData(SimpleReprMixin): def _open_db(self): if self._debug.should('dataio'): self._debug.write("Opening data file {!r}".format(self.filename)) - self._dbs[threading.get_ident()] = Sqlite(self.filename, self._debug) - with self._dbs[threading.get_ident()] as db: + self._dbs[get_thread_id()] = Sqlite(self.filename, self._debug) + with self._dbs[get_thread_id()] as db: try: schema_version, = db.execute("select version from coverage_schema").fetchone() except Exception as exc: @@ -155,15 +160,16 @@ class CoverageSqliteData(SimpleReprMixin): self._file_map[path] = id def _connect(self): - if threading.get_ident() not in self._dbs: + if get_thread_id() not in self._dbs: if os.path.exists(self.filename): self._open_db() else: self._create_db() - return self._dbs[threading.get_ident()] + return self._dbs[get_thread_id()] def __nonzero__(self): - if threading.get_ident() not in self._dbs and not os.path.exists(self.filename): + if (get_thread_id() not in self._dbs and + not os.path.exists(self.filename)): return False try: with self._connect() as con: |