From 7100c2fa74bd70b34ee43472ac8585562ebf77a0 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 23 Sep 2010 15:01:07 +0200 Subject: [PATCH] locking: Don't set default priority as keyword default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows users of these classes to simply pass None if they want to use the default value (the actual default is an internal constant), instead of dynamically constructing the keyword arguments. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: RenΓ© Nussbaumer <rn@google.com> --- lib/locking.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/locking.py b/lib/locking.py index 84268de6e..9304cf9e4 100644 --- a/lib/locking.py +++ b/lib/locking.py @@ -749,7 +749,7 @@ class SharedLock(object): return False - def acquire(self, shared=0, timeout=None, priority=_DEFAULT_PRIORITY, + def acquire(self, shared=0, timeout=None, priority=None, test_notify=None): """Acquire a shared lock. @@ -764,6 +764,9 @@ class SharedLock(object): @param test_notify: Special callback function for unittesting """ + if priority is None: + priority = _DEFAULT_PRIORITY + self.__lock.acquire() try: # We already got the lock, notify now @@ -800,7 +803,7 @@ class SharedLock(object): finally: self.__lock.release() - def delete(self, timeout=None, priority=_DEFAULT_PRIORITY): + def delete(self, timeout=None, priority=None): """Delete a Shared Lock. This operation will declare the lock for removal. First the lock will be @@ -813,6 +816,9 @@ class SharedLock(object): @param priority: Priority for acquiring lock """ + if priority is None: + priority = _DEFAULT_PRIORITY + self.__lock.acquire() try: assert not self.__is_sharer(), "Cannot delete() a lock while sharing it" @@ -992,7 +998,7 @@ class LockSet: self.__lock.release() return set(result) - def acquire(self, names, timeout=None, shared=0, priority=_DEFAULT_PRIORITY, + def acquire(self, names, timeout=None, shared=0, priority=None, test_notify=None): """Acquire a set of resource locks. @@ -1022,6 +1028,9 @@ class LockSet: assert not self._is_owned(), ("Cannot acquire locks in the same set twice" " (lockset %s)" % self.name) + if priority is None: + priority = _DEFAULT_PRIORITY + # We need to keep track of how long we spent waiting for a lock. The # timeout passed to this function is over all lock acquires. running_timeout = RunningTimeout(timeout, False) -- GitLab