本文整理汇总了Python中gevent.coros.Semaphore.locked方法的典型用法代码示例。如果您正苦于以下问题:Python Semaphore.locked方法的具体用法?Python Semaphore.locked怎么用?Python Semaphore.locked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.coros.Semaphore
的用法示例。
在下文中一共展示了Semaphore.locked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BlockingDeque
# 需要导入模块: from gevent.coros import Semaphore [as 别名]
# 或者: from gevent.coros.Semaphore import locked [as 别名]
class BlockingDeque(deque):
def __init__(self, *args, **kwargs):
super(BlockingDeque, self).__init__(*args, **kwargs)
self.sema = Semaphore(len(self))
def append(self, *args, **kwargs):
ret = super(BlockingDeque, self).append(*args, **kwargs)
self.sema.release()
return ret
def appendleft(self, *args, **kwargs):
ret = super(BlockingDeque, self).appendleft(*args, **kwargs)
self.sema.release()
return ret
def clear(self, *args, **kwargs):
ret = super(BlockingDeque, self).clear(*args, **kwargs)
while not self.sema.locked():
self.sema.acquire(blocking=False)
return ret
def extend(self, *args, **kwargs):
pre_n = len(self)
ret = super(BlockingDeque, self).extend(*args, **kwargs)
post_n = len(self)
for i in xrange(pre_n, post_n):
self.sema.release()
return ret
def extendleft(self, *args, **kwargs):
pre_n = len(self)
ret = super(BlockingDeque, self).extendleft(*args, **kwargs)
post_n = len(self)
for i in xrange(pre_n, post_n):
self.sema.release()
return ret
def pop(self, *args, **kwargs):
self.sema.acquire()
return super(BlockingDeque, self).pop(*args, **kwargs)
def popleft(self, *args, **kwargs):
self.sema.acquire()
return super(BlockingDeque, self).popleft(*args, **kwargs)
def remove(self, *args, **kwargs):
ret = super(BlockingDeque, self).remove(*args, **kwargs)
self.sema.acquire()
return ret
示例2: OCCurveManager
# 需要导入模块: from gevent.coros import Semaphore [as 别名]
# 或者: from gevent.coros.Semaphore import locked [as 别名]
class OCCurveManager(object):
def __init__(self, oc_gateway):
self._oc_gateway = oc_gateway
self._model_settings_update_in_progress = Semaphore()
self._vol_curves = {}
self._parent_symbol_to_sandbox_symbol_dict = {}
self._parent_month_id_to_sandbox_month_id_dict = {}
self._vol_curve_factory = VolCurveFactory(oc_gateway)
#######################
# model settings request handling
def get_model_settings(self, month_id):
vol_curve = self._vol_curves.get(month_id)
if not vol_curve:
vol_curve = self._vol_curve_factory.get_vol_curve(month_id)
self._vol_curves[month_id] = vol_curve
return vol_curve.get_curve_settings()
#######################
# synchronization handlers
def on_model_update_notification(self):
if not self._model_settings_update_in_progress.locked():
for month_id, vol_curve in self._vol_curves.iteritems():
vol_curve.refresh_oc_model_settings()
#######################
# model input manipulation utils
def set_model_settings(self, **kwargs):
with self._model_settings_update_in_progress:
month_id = kwargs["month_id"]
vol_curve = self._vol_curves[month_id]
new_settings = vol_curve.set_model_settings(**kwargs)
return new_settings
def move_model_inputs_by_price(self, **kwargs):
with self._model_settings_update_in_progress:
month_id = kwargs["month_id"]
vol_curve = self._vol_curves[month_id]
new_settings = vol_curve.move_inputs_by_price(**kwargs)
return new_settings