util.with_lock: add support for chaining with @event_listener
Consider e.g.:
```
class AddressSynchronizer(Logger, EventListener):
[... snip ...]
@event_listener
@with_lock
def on_event_blockchain_updated(self, *args):
self._get_balance_cache = {} # invalidate cache
self.db.put('stored_height', self.get_local_height())
```
was raising:
```
func.__qualname__='with_lock.<locals>.func_wrapper'
Traceback (most recent call last):
File "...\electrum\run_electrum", line 105, in <module>
from electrum.logging import get_logger, configure_logging # import logging submodule first
File "...\electrum\electrum\__init__.py", line 19, in <module>
from .wallet import Wallet
File "...\electrum\electrum\wallet.py", line 70, in <module>
from .address_synchronizer import (
File "...\electrum\electrum\address_synchronizer.py", line 75, in <module>
class AddressSynchronizer(Logger, EventListener):
File "...\electrum\electrum\address_synchronizer.py", line 205, in AddressSynchronizer
def on_event_blockchain_updated(self, *args):
File "...\electrum\electrum\util.py", line 2005, in event_listener
classname, method_name = func.__qualname__.split('.')
ValueError: too many values to unpack (expected 2)
```
This commit is contained in:
@@ -1243,6 +1243,7 @@ def ignore_exceptions(func):
|
||||
|
||||
def with_lock(func):
|
||||
"""Decorator to enforce a lock on a function call."""
|
||||
@functools.wraps(func)
|
||||
def func_wrapper(self, *args, **kwargs):
|
||||
with self.lock:
|
||||
return func(self, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user