@@ -348,6 +348,7 @@ def acquire_lock(self,
348348 retry_timeout = None ,
349349 additional_attributes = None ,
350350 app_callback = None ,
351+ raise_context_exception = False ,
351352 ):
352353 """
353354 Acquires a distributed DynaomDBLock for the given key(s).
@@ -385,6 +386,7 @@ def acquire_lock(self,
385386 :param dict additional_attributes: Arbitrary application metadata to be stored with the lock
386387 :param Callable app_callback: Callback function that can be used to notify the app of lock entering
387388 the danger period, or an unexpected release
389+ :param bool raise_context_exception: Allow exception in the context to be raised
388390 :rtype: DynamoDBLock
389391 :return: A distributed lock instance
390392 """
@@ -405,6 +407,7 @@ def acquire_lock(self,
405407 additional_attributes = additional_attributes ,
406408 app_callback = app_callback ,
407409 lock_client = self ,
410+ raise_context_exception = raise_context_exception ,
408411 )
409412
410413 start_time = time .monotonic ()
@@ -838,6 +841,7 @@ def __init__(self,
838841 additional_attributes ,
839842 app_callback ,
840843 lock_client ,
844+ raise_context_exception ,
841845 ):
842846 """
843847 :param str partition_key: The primary lock identifier
@@ -851,6 +855,7 @@ def __init__(self,
851855 :param Callable app_callback: Callback function that can be used to notify the app of lock entering
852856 the danger period, or an unexpected release
853857 :param DynamoDBLockClient lock_client: The client that "owns" this lock
858+ :param bool raise_context_exception: Allow exception in the context to be raised
854859 """
855860 BaseDynamoDBLock .__init__ (self ,
856861 partition_key ,
@@ -863,6 +868,7 @@ def __init__(self,
863868 )
864869 self .app_callback = app_callback
865870 self .lock_client = lock_client
871+ self .raise_context_exception = raise_context_exception
866872 # additional properties
867873 self .last_updated_time = time .monotonic ()
868874 self .thread_lock = threading .RLock ()
@@ -883,7 +889,8 @@ def __exit__(self, exc_type, exc_value, traceback):
883889 """
884890 logger .debug ('Exiting: %s' , self .unique_identifier )
885891 self .release (best_effort = True )
886- return True
892+ if not self .raise_context_exception :
893+ return True
887894
888895
889896 def release (self , best_effort = True ):
0 commit comments