本文整理汇总了Python中gevent.lock.BoundedSemaphore方法的典型用法代码示例。如果您正苦于以下问题:Python lock.BoundedSemaphore方法的具体用法?Python lock.BoundedSemaphore怎么用?Python lock.BoundedSemaphore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.lock
的用法示例。
在下文中一共展示了lock.BoundedSemaphore方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import BoundedSemaphore [as 别名]
def __init__(self, value=1, max_waiters=1):
MaxWaitersBoundedSemaphore.__init__(
self, GeventBoundedSemaphore, value, max_waiters)
示例2: create_semaphore
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import BoundedSemaphore [as 别名]
def create_semaphore(max_size, max_waiters, use_greenlets):
if max_size is None:
return DummySemaphore()
elif use_greenlets:
if max_waiters is None:
return GeventBoundedSemaphore(max_size)
else:
return MaxWaitersBoundedSemaphoreGevent(max_size, max_waiters)
else:
if max_waiters is None:
return BoundedSemaphore(max_size)
else:
return MaxWaitersBoundedSemaphoreThread(max_size, max_waiters)
示例3: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import BoundedSemaphore [as 别名]
def __init__(self, config):
self.type = config.get('type', None)
self.config = config
import upstream as upstream_mod
upconfig = config.get('upstream', None)
if upconfig:
uptype = upconfig.get("type", None)
if uptype is None:
raise ConfigError(u'[配置错误] upstream 未配置 type !')
Upstream = upstream_mod.get_upstream(uptype)
if Upstream is None:
raise ConfigError(u'[配置错误] upstream type %s 不被支持!' % uptype)
self.upstream = Upstream(upconfig)
pass
else:
if self.type != 'direct':
self.upstream = upstream_mod.get_upstream('direct')({'type':'direct'})
else:
self.upstream = _socket
self.http_pool = HttpPool(self,lock=BoundedSemaphore)
示例4: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import BoundedSemaphore [as 别名]
def __init__(self, account_id, num_connections, readonly):
log.info('Creating Crispin connection pool',
account_id=account_id, num_connections=num_connections)
self.account_id = account_id
self.readonly = readonly
self._queue = Queue(num_connections, items=num_connections * [None])
self._sem = BoundedSemaphore(num_connections)
self._set_account_info()
示例5: __init__
# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import BoundedSemaphore [as 别名]
def __init__(self, process_identifier, process_number,
poll_interval=SYNC_POLL_INTERVAL):
self.host = platform.node()
self.process_number = process_number
self.process_identifier = process_identifier
self.monitor_cls_for = {mod.PROVIDER: getattr(
mod, mod.SYNC_MONITOR_CLS) for mod in module_registry.values()
if hasattr(mod, 'SYNC_MONITOR_CLS')}
for p_name, p in providers.iteritems():
if p_name not in self.monitor_cls_for:
self.monitor_cls_for[p_name] = self.monitor_cls_for["generic"]
self.log = get_logger()
self.log.bind(process_number=process_number)
self.log.info('starting mail sync process',
supported_providers=module_registry.keys())
self.syncing_accounts = set()
self.email_sync_monitors = {}
self.contact_sync_monitors = {}
self.event_sync_monitors = {}
# Randomize the poll_interval so we maintain at least a little fairness
# when using a timeout while blocking on the redis queues.
min_poll_interval = 5
self.poll_interval = int((random.random() * (poll_interval - min_poll_interval)) + min_poll_interval)
self.semaphore = BoundedSemaphore(1)
self.zone = config.get('ZONE')
# Note that we don't partition by zone for the private queues.
# There's not really a reason to since there's one queue per machine
# anyways. Also, if you really want to send an Account to a mailsync
# machine in another zone you can do so.
self.private_queue = EventQueue(SYNC_EVENT_QUEUE_NAME.format(self.process_identifier))
self.queue_group = EventQueueGroup([
shared_sync_event_queue_for_zone(self.zone),
self.private_queue,
])
self.stealing_enabled = config.get('SYNC_STEAL_ACCOUNTS', True)
self._pending_avgs_provider = None
self.last_unloaded_account = time.time()