Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to raise context exception #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion python_dynamodb_lock/python_dynamodb_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def acquire_lock(self,
retry_timeout=None,
additional_attributes=None,
app_callback=None,
raise_context_exception=False,
):
"""
Acquires a distributed DynaomDBLock for the given key(s).
Expand Down Expand Up @@ -385,6 +386,7 @@ def acquire_lock(self,
:param dict additional_attributes: Arbitrary application metadata to be stored with the lock
:param Callable app_callback: Callback function that can be used to notify the app of lock entering
the danger period, or an unexpected release
:param bool raise_context_exception: Allow exception in the context to be raised
:rtype: DynamoDBLock
:return: A distributed lock instance
"""
Expand All @@ -405,6 +407,7 @@ def acquire_lock(self,
additional_attributes=additional_attributes,
app_callback=app_callback,
lock_client=self,
raise_context_exception=raise_context_exception,
)

start_time = time.monotonic()
Expand Down Expand Up @@ -838,6 +841,7 @@ def __init__(self,
additional_attributes,
app_callback,
lock_client,
raise_context_exception,
):
"""
:param str partition_key: The primary lock identifier
Expand All @@ -851,6 +855,7 @@ def __init__(self,
:param Callable app_callback: Callback function that can be used to notify the app of lock entering
the danger period, or an unexpected release
:param DynamoDBLockClient lock_client: The client that "owns" this lock
:param bool raise_context_exception: Allow exception in the context to be raised
"""
BaseDynamoDBLock.__init__(self,
partition_key,
Expand All @@ -863,6 +868,7 @@ def __init__(self,
)
self.app_callback = app_callback
self.lock_client = lock_client
self.raise_context_exception = raise_context_exception
# additional properties
self.last_updated_time = time.monotonic()
self.thread_lock = threading.RLock()
Expand All @@ -883,7 +889,8 @@ def __exit__(self, exc_type, exc_value, traceback):
"""
logger.debug('Exiting: %s', self.unique_identifier)
self.release(best_effort=True)
return True
if not self.raise_context_exception:
return True


def release(self, best_effort=True):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/mohankishore/python_dynamodb_lock',
version='0.9.1',
version='0.9.2',
zip_safe=False,
)