@@ -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 ()
@@ -837,6 +840,7 @@ def __init__(self,
837840 additional_attributes ,
838841 app_callback ,
839842 lock_client ,
843+ raise_context_exception ,
840844 ):
841845 """
842846 :param str partition_key: The primary lock identifier
@@ -850,6 +854,7 @@ def __init__(self,
850854 :param Callable app_callback: Callback function that can be used to notify the app of lock entering
851855 the danger period, or an unexpected release
852856 :param DynamoDBLockClient lock_client: The client that "owns" this lock
857+ :param bool raise_context_exception: Allow exception in the context to be raised
853858 """
854859 BaseDynamoDBLock .__init__ (self ,
855860 partition_key ,
@@ -862,6 +867,7 @@ def __init__(self,
862867 )
863868 self .app_callback = app_callback
864869 self .lock_client = lock_client
870+ self .raise_context_exception = raise_context_exception
865871 # additional properties
866872 self .last_updated_time = time .monotonic ()
867873 self .thread_lock = threading .RLock ()
@@ -882,7 +888,8 @@ def __exit__(self, exc_type, exc_value, traceback):
882888 """
883889 logger .debug ('Exiting: %s' , self .unique_identifier )
884890 self .release (best_effort = True )
885- return True
891+ if not self .raise_context_exception :
892+ return True
886893
887894
888895 def release (self , best_effort = True ):
0 commit comments