Skip to content

Commit 9002229

Browse files
authored
Merge pull request #2 from cedarai/master
add an option to raise context exception
2 parents e76574e + 00aa374 commit 9002229

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

python_dynamodb_lock/python_dynamodb_lock.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
test_suite='tests',
4545
tests_require=test_requirements,
4646
url='https://github.com/mohankishore/python_dynamodb_lock',
47-
version='0.9.1',
47+
version='0.9.2',
4848
zip_safe=False,
4949
)

0 commit comments

Comments
 (0)