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


Python gevent.queue方法代碼示例

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


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

示例1: make_channel

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def make_channel(self):
    """Returns a single-slot communication device for passing data and control
    between concurrent functions.

    This is useful for running 'background helper' type concurrent processes.

    NOTE: It is strongly discouraged to pass Channel objects outside of a recipe
    module. Access to the channel should be mediated via
    a class/contextmanager/function which you return to the caller, and the
    caller can call in a makes-sense-for-your-moudle's-API way.

    See ./tests/background_helper.py for an example of how to use a Channel
    correctly.

    It is VERY RARE to need to use a Channel. You should avoid using this unless
    you carefully consider and avoid the possibility of introducing deadlocks.

    Channels will raise ValueError if used with @@@annotation@@@ mode.
    """
    if not self.concurrency_client.supports_concurrency: # pragma: no cover
      # test mode always supports concurrency, hence the nocover
      raise ValueError('Channels are not allowed in @@@annotation@@@ mode')
    return gevent.queue.Channel() 
開發者ID:luci,項目名稱:recipes-py,代碼行數:25,代碼來源:api.py

示例2: usecase_child_d

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def usecase_child_d(forthreader, backwriter):
    recvqueue = gevent.queue.Queue()
    def g_from_forthpipe_to_q(forthreader):
        while True:
            m = forthreader.get()
            recvqueue.put(m)
            if m == "STOP":
                break

    def g_from_q_to_backpipe(backwriter):
        while True:
            m = recvqueue.get()
            backwriter.put(m)
            if m == "STOP":
                break

    g1 = gevent.spawn(g_from_forthpipe_to_q, forthreader)
    g2 = gevent.spawn(g_from_q_to_backpipe, backwriter)
    g1.get()
    g2.get() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:22,代碼來源:test_gipc.py

示例3: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def __init__(self, device, prefix, watermark, attributes, persistent):
        super(DevicePusher, self).__init__()

        self.device = device
        self.xapi = pan.xapi.PanXapi(
            tag=self.device.get('tag', None),
            api_username=self.device.get('api_username', None),
            api_password=self.device.get('api_password', None),
            api_key=self.device.get('api_key', None),
            port=self.device.get('port', None),
            hostname=self.device.get('hostname', None),
            serial=self.device.get('serial', None)
        )

        self.valid_device_version = None
        self.prefix = prefix
        self.attributes = attributes
        self.watermark = watermark
        self.persistent = persistent

        self.q = gevent.queue.Queue() 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:23,代碼來源:dag_ng.py

示例4: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def __init__(self, device, prefix, watermark, attributes, persistent):
        super(DevicePusher, self).__init__()

        self.device = device
        self.xapi = pan.xapi.PanXapi(
            tag=self.device.get('tag', None),
            api_username=self.device.get('api_username', None),
            api_password=self.device.get('api_password', None),
            api_key=self.device.get('api_key', None),
            port=self.device.get('port', None),
            hostname=self.device.get('hostname', None),
            serial=self.device.get('serial', None)
        )

        self.prefix = prefix
        self.attributes = attributes
        self.watermark = watermark
        self.persistent = persistent

        self.q = gevent.queue.Queue() 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:22,代碼來源:dag.py

示例5: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def __init__(self, name, chassis, config):
        self.table = None
        self.agg_table = None

        self._actor_queue = gevent.queue.Queue(maxsize=128)
        self._actor_glet = None
        self._actor_commands_ts = collections.defaultdict(int)
        self._poll_glet = None
        self._age_out_glet = None
        self._emit_counter = 0

        self.last_run = None
        self.last_successful_run = None
        self.last_ageout_run = None
        self._sub_state = None
        self._sub_state_message = None

        self.poll_event = gevent.event.Event()

        self.state_lock = RWLock()

        super(BasePollerFT, self).__init__(name, chassis, config) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:24,代碼來源:basepoller.py

示例6: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def __init__(self, id, parser, driver, cpu=None, is_process=True):
        self.parser = parser
        self.driver = driver
        self.id = id

        self._running = False
        self._rpc_task = None
        self._events_task = None
        self._health_task = None

        self.queue = gevent.queue.Queue(maxsize=10000)
        self.cpu = cpu
        self.is_process = is_process

        self.logger = init_logging("main.{}".format(self.id))

        self.error_mr = MetricsRecorder("sniffer.main.error")
        self.msg_mr = MetricsRecorder("sniffer.main.msg")
        self.event_mr = MetricsRecorder("sniffer.main.event")
        self.rpc_mr = MetricsRecorder("sniffer.main.rpc")
        self.main_mr = MetricsRecorder("sniffer.main.loop")

        self.urltree = URLTree() 
開發者ID:threathunterX,項目名稱:sniffer,代碼行數:25,代碼來源:main.py

示例7: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def __init__(self, app):
        log.debug('initializing JSONRPCServer')
        BaseService.__init__(self, app)
        self.app = app

        self.dispatcher = LoggingDispatcher()
        # register sub dispatchers
        for subdispatcher in self.subdispatcher_classes():
            subdispatcher.register(self)

        transport = WsgiServerTransport(queue_class=gevent.queue.Queue)
        # start wsgi server as a background-greenlet
        self.listen_port = app.config['jsonrpc']['listen_port']
        self.listen_host = app.config['jsonrpc']['listen_host']
        self.wsgi_server = gevent.wsgi.WSGIServer((self.listen_host, self.listen_port),
                                                  transport.handle, log=WSGIServerLogger)
        self.rpc_server = RPCServerGreenlets(
            transport,
            JSONRPCProtocol(),
            self.dispatcher
        )
        self.default_block = 'latest' 
開發者ID:heikoheiko,項目名稱:pyethapp,代碼行數:24,代碼來源:jsonrpc.py

示例8: manage

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def manage(self):
        """"
        Manage will hand out work when the appropriate Worker is free.
        The manager timeout must be less than worker timeout, or else, the
        workers will be idled and shutdown.
        """
        try:
            while True:
                for name, workgroup in self.workgroups.items():
                    for qname, q in self.qitems.items():
                        if name == qname: # workgroup name must match tracker name
                            # a tracker with the same name as workgroup name, is...
                            # ...effectively, the workgroup's task queue, so now...
                            # assign a task to a worker from the workgroup's task queue
                            for worker in workgroup:
                                one_task = q.get(timeout=self.mgr_qtimeout)
                                worker.tasks.put(one_task)
                gevent.sleep(0)
        except Empty:
            self.mgr_no_work = True
            if self.mgr_should_stop:
                logger.info(f"Assigned all {name} work. I've been told I should stop.")
                self.should_stop = True
            else:
                logger.info(f"Assigned all {name} work. Awaiting more tasks to assign.") 
開發者ID:bomquote,項目名稱:transistor,代碼行數:27,代碼來源:base_manager.py

示例9: fetch_urls

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def fetch_urls(self, queue, quantity):
        while not queue.empty():
            url = queue.get()
            html = self.s.get(url, headers=self.headers).text
            pq = PyQuery(html)
            size = pq.find('tbody tr').size()
            for index in range(size):
                item = pq.find('tbody tr').eq(index)
                ip = item.find('td').eq(0).text()
                port = item.find('td').eq(1).text()
                _type = item.find('td').eq(3).text()
                self.result_arr.append({
                    str(_type).lower(): '{0}://{1}:{2}'.format(str(_type).lower(), ip, port)
                })
                if len(self.result_arr) >= quantity:
                    break 
開發者ID:MyFaith,項目名稱:Proxies,代碼行數:18,代碼來源:Proxies.py

示例10: _SendLoop

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def _SendLoop(self):
    """Dispatch messages from the send queue to the remote server.

    Note: Messages in the queue have already been serialized into wire format.
    """
    while self.isActive:
      try:
        payload, dct = self._send_queue.get()
        queue_len = self._send_queue.qsize()
        self._varz.send_queue_size(queue_len)
        # HandleTimeout sets up the transport level timeout handling
        # for this message.  If the message times out in transit, this
        # transport will handle sending a Tdiscarded to the server.
        if self._HandleTimeout(dct): continue

        with self._varz.send_time.Measure():
          with self._varz.send_latency.Measure():
            self._socket.write(payload)
        self._varz.messages_sent()
      except Exception as e:
        self._Shutdown(e)
        break 
開發者ID:steveniemitz,項目名稱:scales,代碼行數:24,代碼來源:sink.py

示例11: _concurrent_execute

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def _concurrent_execute(self, context, start_req, parser, pool, pool_size):
        queue = Queue()  # 任務隊列

        # 將初始化請求加入任務隊列
        for r in start_req:
            queue.put_nowait(r)

        if pool is None:
            pool = GeventPool(pool_size)

        greenlets = []

        while True:
            try:
                req = self._check_req(queue.get(timeout=1))
                if req.parser is None:
                    req.parser = parser
                greenlets.append(pool.spawn(req, context, queue))
            except Empty:
                break

        return [greenlet.get() for greenlet in greenlets] 
開發者ID:chihongze,項目名稱:girlfriend,代碼行數:24,代碼來源:crawl.py

示例12: test_create_config

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def test_create_config(zk, test_application_name, long_poll):
    queue = long_poll()

    event = queue.get(timeout=5)
    assert event['message'] == 'all'
    assert event['body'] == {
        'service': {test_application_name: {'stable': {}, 'foo': {}}},
        'switch': {test_application_name: {'stable': {}}},
        'config': {test_application_name: {}},
        'service_info': {},
    }
    assert queue.empty()

    zk.create(
        '/huskar/config/%s/alpha/DB_URL' % test_application_name, 'mysql://',
        makepath=True)
    event = queue.get(timeout=5)
    assert event['message'] == 'update'
    assert event['body'] == {'config': {
        test_application_name: {'alpha': {'DB_URL': {u'value': u'mysql://'}}},
    }} 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:23,代碼來源:test_long_polling.py

示例13: test_delete_config

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def test_delete_config(zk, test_application_name, long_poll):
    zk.create(
        '/huskar/config/%s/alpha/DB_URL' % test_application_name, 'mysql://',
        makepath=True)
    queue = long_poll()

    event = queue.get(timeout=5)
    assert event['message'] == 'all'
    assert event['body'] == {
        'service': {test_application_name: {'stable': {}, 'foo': {}}},
        'switch': {test_application_name: {'stable': {}}},
        'config': {
            test_application_name: {'alpha': {
                'DB_URL': {u'value': u'mysql://'},
            }},
        },
        'service_info': {}
    }

    zk.delete('/huskar/config/%s/alpha/DB_URL' % test_application_name)
    event = queue.get(timeout=5)
    assert event['message'] == 'delete'
    assert event['body'] == {'config': {
        test_application_name: {'alpha': {'DB_URL': {u'value': None}}}
    }} 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:27,代碼來源:test_long_polling.py

示例14: test_tree_broadcast

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def test_tree_broadcast(zk, long_poll, test_application_name):
    zk.create('/huskar/config/%s/alpha/foo' % test_application_name, 'FOO',
              makepath=True)

    queue_a = long_poll()
    queue_b = long_poll()

    for queue in queue_a, queue_b:
        event = queue.get(timeout=5)
        assert event['message'] == 'all'
        assert event['body']['config'] == {
            test_application_name: {'alpha': {'foo': {'value': 'FOO'}}},
        }
        assert queue.empty()

    zk.create('/huskar/config/%s/alpha/bar' % test_application_name, 'BAR',
              makepath=True)

    for queue in queue_a, queue_b:
        event = queue.get(timeout=5)
        assert event['message'] == 'update'
        assert event['body']['config'] == {
            test_application_name: {'alpha': {'bar': {'value': 'BAR'}}},
        }
        assert queue.empty() 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:27,代碼來源:test_long_polling.py

示例15: test_jira_845_regression_1

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import queue [as 別名]
def test_jira_845_regression_1(zk, test_application_name, long_poll):
    """Fix http://jira.ele.to:8088/browse/FXBUG-845."""
    zk.create(
        '/huskar/service/%s/foo/169.254.0.1_5000' % test_application_name,
        '{"ip":"169.254.0.1","port":{"main":5000}}', makepath=True)

    queue = long_poll()

    event = queue.get(timeout=5)
    assert event['message'] == 'all'

    zk.create('/huskar/service/%s/beta' % test_application_name,
              '{"link":["foo"]}', makepath=True)
    zk.create(
        '/huskar/service/%s/foo/169.254.0.2_5000' % test_application_name,
        '', makepath=True)

    event = queue.get(timeout=5)
    assert event['message'] != 'all', 'We should be silent for cluster linking'
    assert queue.empty(), 'We should notify for node creation only' 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:22,代碼來源:test_long_polling.py


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