一个多普勒锁,典型地用作大隐藏溶液的一部分
dogpile.core的Python项目详细描述
一个“dogpile”锁,它允许单个线程生成 一种昂贵的资源,而其他线程使用“旧”值,直到 “新”值已准备好。
dogpile基本上是从 烧杯包装,简单通用。
用法
一个简单的例子:
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()
上面,some_creation_function()将被调用 第一次调用Dogpile.acquire()时。这个 然后,with块的其余部分继续。并发线程 在此初始期间调用Dogpile.acquire()。 将被阻止,直到some_creation_function()完成。
一旦创建功能第一次成功完成, 对Dogpile.acquire()的新调用将调用some_creation_function() 每次到达“expiretime”时,只允许 调用函数的线程。并发线程 在此期间,哪个调用Dogpile.acquire()将 掉下来,不要被堵住。预计 资源的“过时”版本在此仍然可用 生成新的时间。
dogpile.core位于dogpile.cache包的核心 它提供了一个基本的缓存api和基于dogpile概念的示例后端。
发展现状
dogpile.core已经在少数生产环境中使用了一段时间 月,并且从0.3.2开始已经进入beta状态。目前还没有关于其 核心同步模型,总体来说项目没有太多变化。 大多数开发都在dogpile.cache中继续。