@@ -137,7 +137,7 @@ def _send_heartbeat_loop(self):
137137
138138 The method has a while loop that wakes up on a periodic basis (as defined by the _heartbeat_period)
139139 and invokes the _send_heartbeat() method on each lock. It spreads the heartbeat-calls evenly over
140- the heartbeat window - to minimize the DynamoDB write throughput requirements.
140+ the heartbeat window - to minimize the DynamoDB write throughput requirements.
141141 """
142142 while not self ._shutting_down :
143143 logger .info ('Starting a send_heartbeat loop' )
@@ -222,7 +222,7 @@ def _send_heartbeat(self, lock):
222222 ExpressionAttributeValues = {
223223 ':old_rvn' : old_record_version_number ,
224224 ':new_rvn' : new_record_version_number ,
225- ':new_et' : new_expiry_time ,
225+ ':new_et' : new_expiry_time ,
226226 }
227227 )
228228
@@ -292,7 +292,7 @@ def _check_heartbeat(self, lock):
292292
293293 As this method is called on a background thread, it uses the app_callback to let the
294294 (lock requestor) app know when there are significant events in the lock lifecycle.
295-
295+
296296 1) LOCK_IN_DANGER
297297 When the heartbeat for a given lock has failed multiple times, and it is
298298 now in danger of going past its lease-duration without a successful heartbeat - at which
@@ -459,7 +459,10 @@ def acquire_lock(self,
459459 return new_lock
460460 except ClientError as e :
461461 if e .response ['Error' ]['Code' ] == 'ConditionalCheckFailedException' :
462- logger .info ('Someone else beat us to it - just log-it, sleep and retry: %s' , new_lock .unique_identifier )
462+ logger .info (
463+ 'Someone else beat us to it - just log-it, sleep and retry: %s' ,
464+ new_lock .unique_identifier
465+ )
463466 else :
464467 raise DynamoDBLockError (DynamoDBLockError .UNKNOWN , str (e ))
465468 except Exception as e :
@@ -470,7 +473,10 @@ def acquire_lock(self,
470473 curr_loop_end_time = time .monotonic ()
471474 next_loop_start_time = start_time + retry_count * retry_period .total_seconds ()
472475 if next_loop_start_time > retry_timeout_time :
473- raise DynamoDBLockError (DynamoDBLockError .ACQUIRE_TIMEOUT , 'acquire_lock() timed out: ' + new_lock .unique_identifier )
476+ raise DynamoDBLockError (
477+ DynamoDBLockError .ACQUIRE_TIMEOUT ,
478+ 'acquire_lock() timed out: ' + new_lock .unique_identifier
479+ )
474480 elif next_loop_start_time > curr_loop_end_time :
475481 logger .info ('Sleeping before a retry: %s' , new_lock .unique_identifier )
476482 time .sleep (next_loop_start_time - curr_loop_end_time )
@@ -592,7 +598,7 @@ def _overwrite_existing_lock_in_dynamodb(self, lock, record_version_number):
592598 :param DynamoDBLock lock: The new lock instance that needs to overwrite the old one in the database.
593599 :param str record_version_number: The version-number for the old lock instance in the database.
594600 """
595- logger .debug ('Overwriting existing-rvn: %s with new lock: %s' , record_version_number , str (lock ))
601+ logger .debug ('Overwriting existing-rvn: %s with new lock: %s' , record_version_number , str (lock ))
596602 self ._dynamodb_table .put_item (
597603 Item = self ._get_item_from_lock (lock ),
598604 ConditionExpression = 'attribute_exists(#pk) AND attribute_exists(#sk) AND #rvn = :old_rvn' ,
@@ -686,7 +692,7 @@ def close(self, release_locks=False):
686692
687693 def __str__ (self ):
688694 """
689- Returns a readble string representation of this instance.
695+ Returns a readable string representation of this instance.
690696 """
691697 return '%s::%s' % (self .__class__ .__name__ , self .__dict__ )
692698
@@ -703,15 +709,14 @@ def create_dynamodb_table(cls,
703709
704710 """
705711 Helper method to create the DynamoDB table
706-
712+
707713 :param boto3.DynamoDB.Client dynamodb_client: mandatory argument
708714 :param str table_name: defaults to 'DynamoDBLockTable'
709715 :param str partition_key_name: defaults to 'lock_key'
710716 :param str sort_key_name: defaults to 'sort_key'
711717 :param str ttl_attribute_name: defaults to 'expiry_time'
712718 :param int read_capacity: the max TPS for strongly-consistent reads; defaults to 5
713719 :param int write_capacity: the max TPS for write operations; defaults to 5
714- :return:
715720 """
716721 logger .info ("Creating the lock table: %s" , table_name )
717722 dynamodb_client .create_table (
@@ -806,7 +811,7 @@ def __init__(self,
806811
807812 def __str__ (self ):
808813 """
809- Returns a readble string representation of this instance.
814+ Returns a readable string representation of this instance.
810815 """
811816 return '%s::%s' % (self .__class__ .__name__ , self .__dict__ )
812817
@@ -918,5 +923,7 @@ def __init__(self,
918923
919924
920925 def __str__ (self ):
926+ """
927+ Returns a readable string representation of this instance.
928+ """
921929 return "%s: %s - %s" % (self .__class__ .__name__ , self .code , self .message )
922-
0 commit comments