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


Python pool.Group方法代碼示例

本文整理匯總了Python中gevent.pool.Group方法的典型用法代碼示例。如果您正苦於以下問題:Python pool.Group方法的具體用法?Python pool.Group怎麽用?Python pool.Group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gevent.pool的用法示例。


在下文中一共展示了pool.Group方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: forward

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def forward(self,sock,remote_sock,data_timeout=5*60):
        u"""在兩個套接字之間轉發數據(阻塞調用)

在轉發失敗時自動關閉連接。在雙向都出現超時的情況下會關閉連接。

未專門處理 shutdown ,單方向 shutdown 時會關閉雙向鏈接。

"""
        try:
            o = {
                # 最後一次轉發數據的時間 = int(time()*1000)
                'forward_data_time':int(time.time()*1000),
            }
            sock.settimeout(data_timeout)
            remote_sock.settimeout(data_timeout)

            group = Group()
            group.add(gevent.spawn(self.__forwardData,sock,remote_sock,o,data_timeout))
            group.add(gevent.spawn(self.__forwardData,remote_sock,sock,o,data_timeout))
            group.join()
        finally:
            sock.close()
            remote_sock.close() 
開發者ID:GameXG,項目名稱:TcpRoute,代碼行數:25,代碼來源:base.py

示例2: __init__

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def __init__(self, nsqd_tcp_addresses=[], max_backoff_duration=128,
                 **kwargs):
        if not nsqd_tcp_addresses:
            raise ValueError('must specify at least one nsqd or lookupd')

        self.nsqd_tcp_addresses = parse_nsqds(nsqd_tcp_addresses)
        self.max_backoff_duration = max_backoff_duration
        self.conn_kwargs = kwargs
        self.logger = logging.getLogger(__name__)

        self._state = INIT
        self._connections = Queue()
        self._connection_backoffs = defaultdict(self._create_backoff)
        self._response_queues = {}
        self._workers = Group() 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:17,代碼來源:producer.py

示例3: spawn_later

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def spawn_later(self, seconds, func, *args, **kwargs):
        parent = super(GreenletGroupWithExceptionCatching, self)
        func_wrap = self._wrap_errors(func)
        # spawn_later doesn't exist in pool.Group, so let's implement it below
        greenlet = parent.greenlet_class(func_wrap, *args, **kwargs)
        parent.add(greenlet)
        greenlet.start_later(seconds)
        return greenlet 
開發者ID:CounterpartyXCP,項目名稱:counterblock,代碼行數:10,代碼來源:__init__.py

示例4: spawn_imap_unordered

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def spawn_imap_unordered(self):
        igroup = Group()
        result = []
        with tracer.start_active_span('test'):
            for i in igroup.imap_unordered(self.make_http_call, range(3)):
                result.append(i) 
開發者ID:instana,項目名稱:python-sensor,代碼行數:8,代碼來源:test_gevent.py

示例5: parallel_map

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def parallel_map(func, iterable, args=None, kwargs=None, workers=None):
    """Map func on a list using gevent greenlets.

    :param func: function applied on iterable elements
    :type func: function
    :param iterable: elements to map the function over
    :type iterable: iterable
    :param args: arguments of func
    :type args: tuple
    :param kwargs: keyword arguments of func
    :type kwargs: dict
    :param workers: limit the number of greenlets
                    running in parrallel
    :type workers: int
    """
    if args is None:
        args = ()
    if kwargs is None:
        kwargs = {}
    if workers is not None:
        pool = Pool(workers)
    else:
        pool = Group()
    iterable = [pool.spawn(func, i, *args, **kwargs) for i in iterable]
    pool.join(raise_error=True)
    for idx, i in enumerate(iterable):
        i_type = type(i.get())
        i_value = i.get()
        if issubclass(i_type, BaseException):
            raise i_value
        iterable[idx] = i_value
    return iterable 
開發者ID:eonpatapon,項目名稱:contrail-api-cli,代碼行數:34,代碼來源:utils.py

示例6: _filter_transactions

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def _filter_transactions(self, transactions: List[Transaction]) -> List[Transaction]:
        """Filters all transactions in parallel. The results may not have the same order."""
        filter_task_group = pool.Group()
        filter_task_results = filter_task_group.imap_unordered(self._filter_transaction_task, transactions)
        return filter_array(lambda el: el is not None, filter_task_results) 
開發者ID:jansenmarc,項目名稱:WavesGatewayFramework,代碼行數:7,代碼來源:transaction_polling_service.py

示例7: __init__

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def __init__(self, account,
                 heartbeat=1, refresh_frequency=30):
        self.refresh_frequency = refresh_frequency
        self.syncmanager_lock = BoundedSemaphore(1)
        self.saved_remote_folders = None
        self.sync_engine_class = FolderSyncEngine

        self.folder_monitors = Group()
        self.delete_handler = None

        BaseMailSyncMonitor.__init__(self, account, heartbeat) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:13,代碼來源:monitor.py

示例8: __init__

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def __init__(self, topic, channel, nsqd_tcp_addresses=[],
                 lookupd_http_addresses=[], name=None, message_handler=None,
                 max_tries=5, max_in_flight=1, requeue_delay=0,
                 lookupd_poll_interval=60, lookupd_poll_jitter=0.3,
                 low_ready_idle_timeout=10, max_backoff_duration=128,
                 backoff_on_requeue=True, **kwargs):
        if not nsqd_tcp_addresses and not lookupd_http_addresses:
            raise ValueError('must specify at least one nsqd or lookupd')

        self.nsqd_tcp_addresses = parse_nsqds(nsqd_tcp_addresses)
        self.lookupds = parse_lookupds(lookupd_http_addresses)
        self.iterlookupds = cycle(self.lookupds)

        self.topic = topic
        self.channel = channel
        self.max_tries = max_tries
        self.max_in_flight = max_in_flight
        self.requeue_delay = requeue_delay
        self.lookupd_poll_interval = lookupd_poll_interval
        self.lookupd_poll_jitter = lookupd_poll_jitter
        self.low_ready_idle_timeout = low_ready_idle_timeout
        self.backoff_on_requeue = backoff_on_requeue
        self.max_backoff_duration = max_backoff_duration
        self.conn_kwargs = kwargs

        if name:
            self.name = name
        else:
            self.name = '%s.%s.%s' % (__name__, self.topic, self.channel)

        if message_handler is not None:
            self.on_message.connect(message_handler, weak=False)

        self.logger = logging.getLogger(self.name)

        self._state = INIT
        self._redistributed_ready_event = Event()
        self._connection_backoffs = defaultdict(self._create_backoff)
        self._message_backoffs = defaultdict(self._create_backoff)

        self._connections = {}
        self._workers = Group()
        self._killables = Group() 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:45,代碼來源:consumer.py

示例9: create_connection

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def create_connection(self, address, timeout=10):

        ip_list = dnslib.dnsQuery(address[0])

        # 嘗試連接緩存
        route_list = self.get_route_order_ping(address[0],address[1],None)
        if route_list:
            try:
                route = route_list[0]
                hit_ip = route['hit_ip']

                if hit_ip in ip_list:
                    cache_timeout = route['tcp_ping']

                    if cache_timeout<1000:
                        cache_timeout = cache_timeout * 2
                    else:
                        cache_timeout = cache_timeout+1000
                    cache_timeout = int(math.ceil(cache_timeout/1000.0))

                    start_time = int(time.time() * 1000)
                    sock = self._direct_create_connection(address,hit_ip, cache_timeout)
                    t = int(time.time() * 1000) - start_time
                    logging.debug(u'[upstream][RouteCache]%s 緩存記錄 連接 %s(%s):%s 命中。time:%s'%(self.get_display_name(),address[0],hit_ip,address[1],t))
                    self.update_route_ping(address[0],address[1],t,hit_ip)
                    return sock
                else:
                    logging.debug(u'[upstream][RouteCache]%s 緩存記錄 連接 %s(%s):%s IP 不匹配,放棄緩存。'%(self.get_display_name(),address[0],hit_ip,address[1]))
            except:
                t = int(time.time() * 1000) - start_time
                info = traceback.format_exc()
                logging.debug(
                    u'[upstream][RouteCache]%s 緩存記錄 連接 %s(%s):%s 失敗。time:%s' % (self.get_display_name(), address[0],hit_ip, address[1],t))
                logging.debug('%s\r\n\r\n' % info)

        # 緩存失敗,連接全部
        evt = Event()
        group = Group()
        aync_task = DirectAsyncTask(evt, None, group)

        for ip in ip_list:
            group.add(gevent.spawn(self._create_connection,  aync_task, address,ip, timeout))

        # 所有連接失敗時發出通知
        gevent.spawn(self._create_connection_all_end, aync_task)

        evt.wait()
        if aync_task.sock:
            return aync_task.sock
        else:
            raise UpstreamConnectError() 
開發者ID:GameXG,項目名稱:TcpRoute,代碼行數:53,代碼來源:direct.py

示例10: create_connection

# 需要導入模塊: from gevent import pool [as 別名]
# 或者: from gevent.pool import Group [as 別名]
def create_connection(self, address, timeout=10):

        # 嘗試連接緩存
        route_list = self.get_route_order_ping(address[0],address[1],None)
        if route_list:
            try:
                route = route_list[0]

                cache_timeout = route['tcp_ping']

                if cache_timeout<1000:
                    cache_timeout = cache_timeout * 2
                else:
                    cache_timeout = cache_timeout+1000
                cache_timeout = int(math.ceil(cache_timeout/1000.0))

                _upstream = self.upstream_dict.get(route['proxy_name'])
                start_time = int(time.time() * 1000)
                sock = _upstream.create_connection(address, cache_timeout)
                t = int(time.time() * 1000) - start_time
                logging.debug(u'[upstream][RouteCache]%s 緩存記錄 連接 %s:%s 命中。time:%s'%(_upstream.get_display_name(),address[0],address[1],t))
                self.update_route_ping(_upstream.get_name(),address[0],address[1],t)
                return sock
            except:
                t = int(time.time() * 1000) - start_time
                info = traceback.format_exc()
                logging.debug(
                    u'[upstream][RouteCache]%s 緩存記錄 連接 %s:%s 失敗。time:%s' % (_upstream.get_display_name(), address[0], address[1],t))
                logging.debug('%s\r\n\r\n' % info)

        # 緩存失敗,連接全部
        evt = Event()
        group = Group()
        aync_task = MultipathAsyncTask(evt, None, group)

        for _upstream in self.upstream_dict.values():
            group.add(gevent.spawn(self._create_connection, _upstream, aync_task, address, timeout))

        # 所有連接失敗時發出通知
        gevent.spawn(self._create_connection_all_end, aync_task)

        evt.wait()
        if aync_task.sock:
            return aync_task.sock
        else:
            raise UpstreamConnectError() 
開發者ID:GameXG,項目名稱:TcpRoute,代碼行數:48,代碼來源:multipath.py


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