-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/improve-login-dialog
- Loading branch information
Showing
23 changed files
with
2,205 additions
and
657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from .db import ( # noqa: F401 | ||
ankihub_db, | ||
attach_ankihub_db_to_anki_db_connection, | ||
attached_ankihub_db, | ||
detach_ankihub_db_from_anki_db_connection, | ||
detached_ankihub_db, | ||
is_ankihub_db_attached_to_anki_db, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""This module defines a readers-writer lock for the AnkiHub DB. | ||
Multiple threads can enter the non_exclusive_db_access_context() context, but when | ||
a thread enters the exclusive_db_access_context() context, no other thread can enter | ||
either context until the thread that entered the exclusive_db_access_context() context | ||
exits it. | ||
""" | ||
from contextlib import contextmanager | ||
|
||
from readerwriterlock import rwlock | ||
|
||
from .. import LOGGER | ||
from .exceptions import LockAcquisitionTimeoutError | ||
|
||
LOCK_TIMEOUT_SECONDS = 5 | ||
|
||
rw_lock = rwlock.RWLockFair() | ||
write_lock = rw_lock.gen_wlock() | ||
|
||
|
||
@contextmanager | ||
def exclusive_db_access_context(): | ||
if write_lock.acquire(blocking=True, timeout=LOCK_TIMEOUT_SECONDS): | ||
LOGGER.debug("Acquired exclusive access.") | ||
try: | ||
yield | ||
finally: | ||
write_lock.release() | ||
LOGGER.debug("Released exclusive access.") | ||
else: | ||
raise LockAcquisitionTimeoutError("Could not acquire exclusive access.") | ||
|
||
|
||
@contextmanager | ||
def non_exclusive_db_access_context(): | ||
lock = rw_lock.gen_rlock() | ||
if lock.acquire(blocking=True, timeout=LOCK_TIMEOUT_SECONDS): | ||
LOGGER.debug("Acquired non-exclusive access.") | ||
try: | ||
yield | ||
finally: | ||
lock.release() | ||
LOGGER.debug("Released non-exclusive access.") | ||
else: | ||
raise LockAcquisitionTimeoutError("Could not acquire non-exclusive access.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.