當前位置: 首頁>>代碼示例>>Python>>正文


Python lock.BoundedSemaphore方法代碼示例

本文整理匯總了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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:thread_util.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:thread_util.py

示例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) 
開發者ID:GameXG,項目名稱:TcpRoute,代碼行數:28,代碼來源:base.py

示例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() 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:10,代碼來源:crispin.py

示例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() 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:44,代碼來源:service.py


注:本文中的gevent.lock.BoundedSemaphore方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。