mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
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.
This commit is contained in:
parent
164559ad7a
commit
78f41d32ce
4 changed files with 11 additions and 11 deletions
|
|
@ -34,3 +34,5 @@ def test_legacy_status(status_dict):
|
|||
assert meta2_a.to_status() == meta_a
|
||||
assert meta2_b.to_status() == meta_b
|
||||
assert ident_a == ident_b == ident
|
||||
|
||||
status.close()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
from copy import deepcopy
|
||||
|
||||
import aiostream
|
||||
|
|
@ -25,13 +26,12 @@ from vdirsyncer.sync.status import SqliteStatus
|
|||
from vdirsyncer.vobject import Item
|
||||
|
||||
|
||||
async def sync(a, b, status, *args, **kwargs):
|
||||
new_status = SqliteStatus(":memory:")
|
||||
new_status.load_legacy_status(status)
|
||||
rv = await _sync(a, b, new_status, *args, **kwargs)
|
||||
status.clear()
|
||||
status.update(new_status.to_legacy_status())
|
||||
return rv
|
||||
async def sync(a, b, status, *args, **kwargs) -> None:
|
||||
with contextlib.closing(SqliteStatus(":memory:")) as new_status:
|
||||
new_status.load_legacy_status(status)
|
||||
await _sync(a, b, new_status, *args, **kwargs)
|
||||
status.clear()
|
||||
status.update(new_status.to_legacy_status())
|
||||
|
||||
|
||||
def empty_storage(x):
|
||||
|
|
|
|||
|
|
@ -232,7 +232,8 @@ def manage_sync_status(base_path: str, pair_name: str, collection_name: str):
|
|||
prepare_status_path(path)
|
||||
status = SqliteStatus(path)
|
||||
|
||||
yield status
|
||||
with contextlib.closing(status):
|
||||
yield status
|
||||
|
||||
|
||||
def save_status(
|
||||
|
|
|
|||
|
|
@ -174,9 +174,6 @@ class SqliteStatus(_StatusBase):
|
|||
self._c.close()
|
||||
self._c = None
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def _is_latest_version(self):
|
||||
try:
|
||||
return bool(
|
||||
|
|
|
|||
Loading…
Reference in a new issue