locking: Don't set default priority as keyword default
authorMichael Hanselmann <hansmi@google.com>
Thu, 23 Sep 2010 13:01:07 +0000 (15:01 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 24 Sep 2010 15:18:43 +0000 (17:18 +0200)
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

index 84268de..9304cf9 100644 (file)
@@ -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)