Skip to content

Commit 8624ce9

Browse files
committed
fix: really turn off SQLite journal files on 3.12+
1 parent 604aafa commit 8624ce9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Unreleased
2929
data files. Now they are always ignored, fixing `issue 1605`_. Thanks to
3030
Brad Smith for suggesting fixes and providing detailed debugging.
3131

32+
- On Python 3.12+, we now disable SQLite writing journal files, which should be
33+
a little faster.
34+
3235
.. _issue 1605: https://github.com/nedbat/coveragepy/pull/1605
3336
.. _issue 1684: https://github.com/nedbat/coveragepy/issues/1684
3437
.. _pull 1685: https://github.com/nedbat/coveragepy/pull/1685

coverage/sqlitedb.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ def _connect(self) -> None:
5555

5656
self.con.create_function("REGEXP", 2, lambda txt, pat: re.search(txt, pat) is not None)
5757

58+
# Turning off journal_mode can speed up writing. It can't always be
59+
# disabled, so we have to be prepared for *-journal files elsewhere.
60+
# In Python 3.12+, we can change the config to allow journal_mode=off.
61+
if hasattr(sqlite3, "SQLITE_DBCONFIG_DEFENSIVE"):
62+
# Turn off defensive mode, so that journal_mode=off can succeed.
63+
self.con.setconfig( # type: ignore[attr-defined]
64+
sqlite3.SQLITE_DBCONFIG_DEFENSIVE, False
65+
)
66+
5867
# This pragma makes writing faster. It disables rollbacks, but we never need them.
5968
self.execute_void("pragma journal_mode=off")
69+
6070
# This pragma makes writing faster. It can fail in unusual situations
6171
# (https://github.com/nedbat/coveragepy/issues/1646), so use fail_ok=True
6272
# to keep things going.

0 commit comments

Comments
 (0)