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

Release locks on error #275

Merged
merged 3 commits into from
Aug 23, 2021
Merged

Release locks on error #275

merged 3 commits into from
Aug 23, 2021

Conversation

rwb27
Copy link
Contributor

@rwb27 rwb27 commented Aug 23, 2021

There's a difference in behaviour between:

l = StrictLock()

with l:
    raise Exception

and

with l():
    raise Exception

The code that implements the latter (to allow arguments) does not release the lock if an error occurs. This is now fixed, and a test is added to check both code paths.

Closes #274

If a lock is acquired using a `with` block, and an exception occurs
within that block, it should still be released.
This commit uses a `try:` `finally:` structure to do this.
StrictLock and CompositeLock can be used as context managers in 2 ways.
They are context manager classes (__enter__ and __exit__ methods) but
the __call__ method is a generator context manager too - allowing
arguments.

This code now tests both forms.
@rwb27 rwb27 merged commit 2ef7a8d into master Aug 23, 2021
@rwb27 rwb27 deleted the release-locks-on-error branch August 23, 2021 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Locks don't get released if exceptions occur within with blocks
1 participant