def synchronized(func):
"""Decorator for storage-access methods, which synchronizes on a threading
lock. The parent object must have 'is_closed' and '_sync_lock' attributes.
"""
@wraps(func)
def synchronized_wrapper(self, *args, **kwargs):
with self._sync_lock:
return func(self, *args, **kwargs)
return synchronized_wrapper
the code is in whoosh/src/util.py,I can’t understand the synchronized_wrapper’s effect and the parameters in synchronized_wrapper(self, *args, **kwargs) from where. Can anyone give me some pointers?
The
@wrapsdecorator is just syntactic sugar for a function closure with argument forwarding.*argsrefers to a tuple of positional args, and**kwargsrefers to a dict of all keyword args that have been passed tofunc.Hence if you had:
and did:
it would basically be like calling:
but inside the “
with self._sync_lock:” context manager