Skip to content

Commit 93971a3

Browse files
committed
Explicitly close status database
Using `__del__` often closes the database on a different thread, which is not supported by the sqlite module and produces a different warning. Explicitly close the status database everywhere it is used.
1 parent 2e55741 commit 93971a3

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

tests/unit/sync/test_status.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ def test_legacy_status(status_dict):
3434
assert meta2_a.to_status() == meta_a
3535
assert meta2_b.to_status() == meta_b
3636
assert ident_a == ident_b == ident
37+
38+
status.close()

tests/unit/sync/test_sync.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4+
import contextlib
45
from copy import deepcopy
56

67
import aiostream
@@ -25,13 +26,12 @@
2526
from vdirsyncer.vobject import Item
2627

2728

28-
async def sync(a, b, status, *args, **kwargs):
29-
new_status = SqliteStatus(":memory:")
30-
new_status.load_legacy_status(status)
31-
rv = await _sync(a, b, new_status, *args, **kwargs)
32-
status.clear()
33-
status.update(new_status.to_legacy_status())
34-
return rv
29+
async def sync(a, b, status, *args, **kwargs) -> None:
30+
with contextlib.closing(SqliteStatus(":memory:")) as new_status:
31+
new_status.load_legacy_status(status)
32+
await _sync(a, b, new_status, *args, **kwargs)
33+
status.clear()
34+
status.update(new_status.to_legacy_status())
3535

3636

3737
def empty_storage(x):

vdirsyncer/cli/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ def manage_sync_status(base_path: str, pair_name: str, collection_name: str):
232232
prepare_status_path(path)
233233
status = SqliteStatus(path)
234234

235-
yield status
235+
with contextlib.closing(status):
236+
yield status
236237

237238

238239
def save_status(

vdirsyncer/sync/status.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ def close(self):
174174
self._c.close()
175175
self._c = None
176176

177-
def __del__(self):
178-
self.close()
179-
180177
def _is_latest_version(self):
181178
try:
182179
return bool(

0 commit comments

Comments
 (0)