Pull requests

#1 Declined
Repository
wooparadog
Branch
abstract-release-exception
Repository
zzzeek
Branch
master

Wrap exception raised by backend when releasing lock, and attach generated result to it.

Author
  1. wooparadog
Reviewers
Description

For #22 of dogpile.cache, aims to raise exception when backend fails to release lock and keep track of generated result at the same time.

  1. Refactor Lock._enter_create.
  2. Add NeedAsyncRegenerationException, which would trigger an async regeneration. It also hold an existing_value for results generated at the moment.
  3. Add LockReleaseException, wraps any exception raised by backend when releasing lock. It also contains results that would be returned if no exception is raised.
  • Learn about pull requests

Comments (5)

  1. Mike Bayer repo owner

    I had envisioned just the try/except around release(). What's all this "would trigger an async regeneration" stuff? why are we refactoring?

  2. wooparadog author

    Mike Bayer I did too. But I tried to keep the generated value in the exception we are going to raise. That means making a variable referencing the value, and in finally, attach that variable to the exception to be raised. I initially wrote gist, then I don't want repeat return return_val and wanted the logic to be clearer here, thus the refactoring and creating NeedAsyncRegenerationException.

    I admit I over did it a little. If you didn't see it fit, please let me know how to improve it or rework it, I hope to learn a lot from here :D.

  3. Mike Bayer repo owner

    keeping in mind I look at this code like once a year these days, how about this:

    diff --git a/dogpile/core/dogpile.py b/dogpile/core/dogpile.py
    index 2e3ca0e..4ab52b0 100644
    --- a/dogpile/core/dogpile.py
    +++ b/dogpile/core/dogpile.py
    @@ -127,6 +127,7 @@ class Lock(object):
                 log.debug("no value, waiting for create lock")
                 self.mutex.acquire()
    
    +        value = NO_VALUE = object()
             try:
                 log.debug("value creation lock %r acquired" % self.mutex)
    
    @@ -150,7 +151,14 @@ class Lock(object):
                 return created
             finally:
                 if not async:
    -                self.mutex.release()
    +                try:
    +                    self.mutex.release()
    +                except:
    +                    if self.only_warn_on_release_failure \
    +                            and value is not NO_VALUE:
    +                        raise LockReleaseFailure(value)
    +                    else:
    +                        raise
                     log.debug("Released creation lock")