1. Michael Bayer
  2. dogpile.core
  3. Pull requests

Pull requests

#1 Declined

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

  1. wooparadog

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.

Comments (5)

  1. wooparadog author

    Michael 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.

  2. Michael 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")
    +        value = NO_VALUE = object()
                 log.debug("value creation lock %r acquired" % self.mutex)
    @@ -150,7 +151,14 @@ class Lock(object):
                 return created
                 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")