Improve docs.
authorScott Gasch <[email protected]>
Tue, 23 Aug 2022 16:59:49 +0000 (09:59 -0700)
committerScott Gasch <[email protected]>
Tue, 23 Aug 2022 16:59:49 +0000 (09:59 -0700)
zookeeper.py

index 39730fa141ced8aff75da0fd4281bb0a29234dff..2b50059fb9153234382e5bec6a5dc2d523e3a98f 100644 (file)
@@ -57,7 +57,6 @@ class RenewableReleasableLease(NonBlockingLease):
     expired or released lease by calling renew.  Go create a new lease
     object at that point.  Finally, note that when you renew the lease
     it will evaluate to False briefly as it is reobtained.
-
     """
 
     def __init__(
@@ -75,7 +74,12 @@ class RenewableReleasableLease(NonBlockingLease):
         self.utcnow = utcnow
 
     def release(self) -> bool:
-        """Release the lease, if it's presently being held."""
+        """Release the lease, if it's presently being held.
+
+        Returns:
+            True if the lease was successfully released,
+            False otherwise.
+        """
         self.client.ensure_path(self.path)
         holder_path = self.path + "/lease_holder"
         lock = self.client.Lock(self.path, self.identifier)
@@ -102,6 +106,19 @@ class RenewableReleasableLease(NonBlockingLease):
         return False
 
     def try_renew(self, duration: datetime.timedelta) -> bool:
+        """Attempt to renew a lease that is currently held.  Note that
+        this will cause self to evaluate to False briefly as the lease
+        is renewed.
+
+        Args:
+            duration: the amount of additional time to add to the
+                      current lease expiration.
+
+        Returns:
+            True if the lease was successfully renewed,
+            False otherwise.
+        """
+
         if not self.obtained:
             return False
         self.obtained = False
@@ -124,6 +141,11 @@ class RenewableReleasableLease(NonBlockingLease):
         return False
 
     def __bool__(self):
+        """Note that this implementation differs from that of the base
+        class in that it probes zookeeper to ensure that the lease is
+        not yet expired and is therefore more expensive.
+        """
+
         if not self.obtained:
             return False
         lock = self.client.Lock(self.path, self.identifier)