mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +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_a.to_status() == meta_a
|
||||||
assert meta2_b.to_status() == meta_b
|
assert meta2_b.to_status() == meta_b
|
||||||
assert ident_a == ident_b == ident
|
assert ident_a == ident_b == ident
|
||||||
|
|
||||||
|
status.close()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
import aiostream
|
import aiostream
|
||||||
|
|
@ -25,13 +26,12 @@ from vdirsyncer.sync.status import SqliteStatus
|
||||||
from vdirsyncer.vobject import Item
|
from vdirsyncer.vobject import Item
|
||||||
|
|
||||||
|
|
||||||
async def sync(a, b, status, *args, **kwargs):
|
async def sync(a, b, status, *args, **kwargs) -> None:
|
||||||
new_status = SqliteStatus(":memory:")
|
with contextlib.closing(SqliteStatus(":memory:")) as new_status:
|
||||||
new_status.load_legacy_status(status)
|
new_status.load_legacy_status(status)
|
||||||
rv = await _sync(a, b, new_status, *args, **kwargs)
|
await _sync(a, b, new_status, *args, **kwargs)
|
||||||
status.clear()
|
status.clear()
|
||||||
status.update(new_status.to_legacy_status())
|
status.update(new_status.to_legacy_status())
|
||||||
return rv
|
|
||||||
|
|
||||||
|
|
||||||
def empty_storage(x):
|
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)
|
prepare_status_path(path)
|
||||||
status = SqliteStatus(path)
|
status = SqliteStatus(path)
|
||||||
|
|
||||||
yield status
|
with contextlib.closing(status):
|
||||||
|
yield status
|
||||||
|
|
||||||
|
|
||||||
def save_status(
|
def save_status(
|
||||||
|
|
|
||||||
|
|
@ -174,9 +174,6 @@ class SqliteStatus(_StatusBase):
|
||||||
self._c.close()
|
self._c.close()
|
||||||
self._c = None
|
self._c = None
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def _is_latest_version(self):
|
def _is_latest_version(self):
|
||||||
try:
|
try:
|
||||||
return bool(
|
return bool(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue