mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Make debug db locking a little nicer to use
This commit is contained in:
parent
a6b6d83d31
commit
df6ddce8a2
@ -5,10 +5,9 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import traceback, sys
|
import traceback, sys, os
|
||||||
from threading import Lock, Condition, current_thread
|
from threading import Lock, Condition, current_thread
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from calibre.utils.config_base import tweaks
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
@ -57,7 +56,7 @@ def create_locks():
|
|||||||
the possibility of deadlocking in this scenario).
|
the possibility of deadlocking in this scenario).
|
||||||
'''
|
'''
|
||||||
l = SHLock()
|
l = SHLock()
|
||||||
wrapper = DebugRWLockWrapper if tweaks.get('newdb_debug_locking', False) else RWLockWrapper
|
wrapper = DebugRWLockWrapper if os.environ.get('CALIBRE_DEBUG_DB_LOCKING') == '1' else RWLockWrapper
|
||||||
return wrapper(l), wrapper(l, is_shared=False)
|
return wrapper(l), wrapper(l, is_shared=False)
|
||||||
|
|
||||||
|
|
||||||
@ -244,22 +243,28 @@ class DebugRWLockWrapper(RWLockWrapper):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
RWLockWrapper.__init__(self, *args, **kwargs)
|
RWLockWrapper.__init__(self, *args, **kwargs)
|
||||||
|
self.print_lock = Lock()
|
||||||
|
|
||||||
def acquire(self):
|
def acquire(self):
|
||||||
print('#' * 120, file=sys.stderr)
|
with self.print_lock:
|
||||||
print('acquire called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
|
print('#' * 120, file=sys.stderr)
|
||||||
traceback.print_stack()
|
print('acquire called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
|
||||||
|
traceback.print_stack()
|
||||||
RWLockWrapper.acquire(self)
|
RWLockWrapper.acquire(self)
|
||||||
print('acquire done: thread id:', current_thread(), file=sys.stderr)
|
with self.print_lock:
|
||||||
print('_' * 120, file=sys.stderr)
|
print('acquire done: thread id:', current_thread(), file=sys.stderr)
|
||||||
|
print('_' * 120, file=sys.stderr)
|
||||||
|
|
||||||
def release(self, *args):
|
def release(self, *args):
|
||||||
print('*' * 120, file=sys.stderr)
|
with self.print_lock:
|
||||||
print('release called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
|
print('*' * 120, file=sys.stderr)
|
||||||
traceback.print_stack()
|
print('release called: thread id:', current_thread(), 'shared:', self._is_shared, file=sys.stderr)
|
||||||
|
traceback.print_stack()
|
||||||
RWLockWrapper.release(self)
|
RWLockWrapper.release(self)
|
||||||
print('release done: thread id:', current_thread(), 'is_shared:', self._shlock.is_shared, 'is_exclusive:', self._shlock.is_exclusive, file=sys.stderr)
|
with self.print_lock:
|
||||||
print('_' * 120, file=sys.stderr)
|
print('release done: thread id:', current_thread(), 'is_shared:', self._shlock.is_shared, 'is_exclusive:', self._shlock.is_exclusive,
|
||||||
|
file=sys.stderr)
|
||||||
|
print('_' * 120, file=sys.stderr)
|
||||||
|
|
||||||
__enter__ = acquire
|
__enter__ = acquire
|
||||||
__exit__ = release
|
__exit__ = release
|
||||||
|
Loading…
x
Reference in New Issue
Block a user