RETIRED, further work has moved to Debian project infrastructure
Go to file
Mike Bayer 661aac8411 - put up EOL 2016-05-30 16:45:44 -04:00
docs/build - put up EOL 2016-05-30 16:45:44 -04:00
dogpile - put up EOL 2016-05-30 16:45:44 -04:00
tests - add a conftest to turn on logging config 2014-04-11 14:32:30 -04:00
.gitignore setup for git 2013-06-21 19:49:52 -04:00
LICENSE 2013 copyright 2013-01-19 12:09:40 -05:00
MANIFEST.in nose config 2012-04-14 18:49:07 -04:00
README.rst - put up EOL 2016-05-30 16:45:44 -04:00
nose_logging_config.ini renaming to dogpile.core so that we are doing a more traditional namespace 2012-04-14 18:00:31 -04:00
setup.cfg add support for py.test 2014-04-11 14:26:57 -04:00
setup.py Updating setup.py so tests aren't globally installed. 2012-09-25 16:02:00 -05:00

README.rst

dogpile.core

Note

The dogpile.core package has been rolled into dogpile.cache directly. dogpile.core as a separate package is effectively EOL.

A "dogpile" lock, one which allows a single thread to generate an expensive resource while other threads use the "old" value, until the "new" value is ready.

Dogpile is basically the locking code extracted from the Beaker package, for simple and generic usage.

Usage

A simple example:

from dogpile.core import Dogpile

# store a reference to a "resource", some
# object that is expensive to create.
the_resource = [None]

def some_creation_function():
    # create the resource here
    the_resource[0] = create_some_resource()

def use_the_resource():
    # some function that uses
    # the resource.  Won't reach
    # here until some_creation_function()
    # has completed at least once.
    the_resource[0].do_something()

# create Dogpile with 3600 second
# expiry time
dogpile = Dogpile(3600)

with dogpile.acquire(some_creation_function):
    use_the_resource()

Above, some_creation_function() will be called when Dogpile.acquire() is first called. The remainder of the with block then proceeds. Concurrent threads which call Dogpile.acquire() during this initial period will be blocked until some_creation_function() completes.

Once the creation function has completed successfully the first time, new calls to Dogpile.acquire() will call some_creation_function() each time the "expiretime" has been reached, allowing only a single thread to call the function. Concurrent threads which call Dogpile.acquire() during this period will fall through, and not be blocked. It is expected that the "stale" version of the resource remain available at this time while the new one is generated.

dogpile.core is at the core of the dogpile.cache package which provides for a basic cache API and sample backends based on the dogpile concept.

Development Status

dogpile.core has been in use in a small number of production environments for a period of months, and as of 0.3.2 has entered beta status. No issues have been reported yet with its core synchronization model, and overall the project hasn't seen many changes. Most development continues within dogpile.cache.