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


Python gevent.joinall方法代碼示例

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


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

示例1: test_two_callbacks

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def test_two_callbacks(self):
        response_greenlet1 = gevent.spawn(self.client.send_task, 'message1')
        response_greenlet2 = gevent.spawn(self.client.send_task, 'message2')

        gevent.joinall([response_greenlet1, response_greenlet2])

        self.assertEquals('message1::response', response_greenlet1.get())
        self.assertEquals('message2::response', response_greenlet2.get())

        spans = self.tracer.finished_spans()
        self.assertEquals(len(spans), 2)

        for span in spans:
            self.assertEquals(span.tags.get(tags.SPAN_KIND, None),
                              tags.SPAN_KIND_RPC_CLIENT)

        self.assertNotSameTrace(spans[0], spans[1])
        self.assertIsNone(spans[0].parent_id)
        self.assertIsNone(spans[1].parent_id) 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:21,代碼來源:test_gevent.py

示例2: test_main

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def test_main(self):
        def main_task():
            with self.tracer.start_active_span('parent'):
                tasks = self.submit_callbacks()
                gevent.joinall(tasks)

        gevent.spawn(main_task)
        gevent.wait(timeout=5.0)

        spans = self.tracer.finished_spans()
        self.assertEquals(len(spans), 4)
        self.assertNamesEqual(spans, ['task', 'task', 'task', 'parent'])

        for i in range(3):
            self.assertSameTrace(spans[i], spans[-1])
            self.assertIsChildOf(spans[i], spans[-1]) 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:18,代碼來源:test_gevent.py

示例3: child_client_runner

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def child_client_runner(server_address):
    """I am executed in a child process.

    Run many HTTP clients, each in its own greenlet. Each HTTP client
        - establishes a TCP connection to the server running in the parent
        - sends an HTTP request through it
        - reads the HTTP response and validates the response body
    """

    def get():
        body = request.urlopen('http://%s:%s/' % server_address).read()
        assert body == DUMMY_PAYLOAD

    t0 = time.time()
    clients = [gevent.spawn(get) for _ in range(N_HTTP_CLIENTS)]

    # Wait until all `get()` greenlet instances have completed.
    gevent.joinall(clients)
    duration = time.time() - t0
    print('%s HTTP clients served within %.2f s.' % (N_HTTP_CLIENTS, duration)) 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:22,代碼來源:wsgimultiprocessing.py

示例4: coroutine_response

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def coroutine_response(self, size=None, stream=False, exception_handler=None, status_only=False):
        g_requests = list(self.__grequests)

        pool = Pool(size) if size else None
        jobs = [send(r, pool, stream=stream) for r in g_requests]
        gevent.joinall(jobs)

        ret = []
        if status_only:
            for request in g_requests:
                if request.response:
                    ret.append(copy.copy(True))
                else:
                    ret.append(copy.copy(False))
            return ret

        for request in g_requests:
            if request.response:
                ret.append(request.response)
            elif exception_handler:
                exception_handler(request, request.exception)



        return ret 
開發者ID:bluedazzle,項目名稱:django-angularjs-blog,代碼行數:27,代碼來源:NetProcess.py

示例5: resolve_hostnames

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def resolve_hostnames(hostnames, timeout):
    """
    Do DNS resolution for a given list of hostnames

    This function uses gevent to resolve all the hostnames in *parallel*

    Args:
        hostnames (list): A list of strings
        timeout (int): The number of seconds to wait for resolution of **all** hostnames

    Returns:
        list: A list of (hostname, address) tuples in the same order as the input list of hostnames

    """
    assert validators.PanoptesValidators.valid_nonempty_iterable_of_strings(hostnames), u'hostnames should be a list'
    assert validators.PanoptesValidators.valid_nonzero_integer(timeout), u'timeout should be an int greater than zero'

    jobs = [gevent.spawn(wrap_errors(gaierror, socket.gethostbyname), host) for host in hostnames]
    gevent.joinall(jobs, timeout=timeout)
    addresses = [job.value if not isinstance(job.get(), gaierror) else None for job in jobs]
    results = [(hostnames[i], result) for i, result in enumerate(addresses)]
    return results 
開發者ID:yahoo,項目名稱:panoptes,代碼行數:24,代碼來源:helpers.py

示例6: get_hostnames

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def get_hostnames(ips, timeout):
    """
    Do DNS resolution for a given list of IPs

    Args:
        ips (list): A list of IPs
        timeout (int): The number of seconds to wait for resolution of **all** IPs

    Returns:
        list: A list of (address, hosname) tuples in the same order as the input list of IPs
    """
    assert validators.PanoptesValidators.valid_nonempty_iterable_of_strings(ips), u'ips should be a list'
    assert validators.PanoptesValidators.valid_nonzero_integer(timeout), u'timeout should be an int greater than zero'

    jobs = [gevent.spawn(wrap_errors((gaierror, herror), socket.gethostbyaddr), ip) for ip in ips]
    gevent.joinall(jobs, timeout=timeout)
    hostnames = [None if isinstance(job.get(), (gaierror, herror)) else job.value for job in jobs]
    results = {
        ips[i]: unknown_hostname(ips[i]) if ((not result) or
                                             (not result[0]) or
                                             result[0].startswith(u'UNKNOWN'))
        else result[0]
        for i, result in enumerate(hostnames)}
    return results 
開發者ID:yahoo,項目名稱:panoptes,代碼行數:26,代碼來源:helpers.py

示例7: test_async_publish

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def test_async_publish():
    with NsqdIntegrationServer() as server:
        results = []
        producer = Producer(server.tcp_address)
        producer.start()

        for _ in range(100):
            results.append(producer.publish('test', b'hi', raise_error=False))

        gevent.joinall(results, raise_error=True)
        producer.close()
        producer.join()

        conn = NsqdHTTPClient(server.address, server.http_port)
        stats = conn.stats()

        assert stats['topics'][0]['depth'] == 100 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:19,代碼來源:test_producer.py

示例8: test_async_multipublish

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def test_async_multipublish():
    with NsqdIntegrationServer() as server:
        results = []
        producer = Producer(server.tcp_address)
        producer.start()

        for _ in range(10):
            result = producer.multipublish(
                'test', 10 * [b'hi'], raise_error=False)
            results.append(result)

        gevent.joinall(results, raise_error=True)
        producer.close()
        producer.join()

        conn = NsqdHTTPClient(server.address, server.http_port)
        stats = conn.stats()

        assert stats['topics'][0]['depth'] == 100 
開發者ID:wtolson,項目名稱:gnsq,代碼行數:21,代碼來源:test_producer.py

示例9: _run_no_wait_ops

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def _run_no_wait_ops(state):
    '''
    Run all ops for all servers at once.
    '''

    hosts_operations = product(state.inventory, state.get_op_order())
    with progress_spinner(hosts_operations) as progress:
        # Spawn greenlet for each host to run *all* ops
        greenlets = [
            state.pool.spawn(
                _run_server_ops, state, host,
                progress=progress,
            )
            for host in state.inventory
        ]
        gevent.joinall(greenlets) 
開發者ID:Fizzadar,項目名稱:pyinfra,代碼行數:18,代碼來源:operations.py

示例10: testGevent

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def testGevent():

    # 創建一個協程對象,創建的時候就自動運行了,不需要手動啟動
    g1 = gevent.spawn(work5, 10)
    g2 = gevent.spawn(work5, 10)
    g3 = gevent.spawn(work5, 10)

    # 阻塞等待協程執行完畢
    # 沒使用monkey.patch_all()破解的時候不會自動切換,破解後就會隨機協程
    # g1.join()
    # g2.join()
    # g3.join()

    # 程序從上到下執行,不管之前有沒有異步代碼,遇到join相當於一麵牆,堵住下麵的路
    gevent.joinall([g1,g2,g3])

    print("全部協程結束完畢.") 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:19,代碼來源:basic01.py

示例11: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def __init__(self, target=''):
        Greenlet.__init__(self)
        self.target=target
        r=requests.get(target)
        self.headers=r.headers
        self.content=r.content

        gevent.spawn(self.loadplugins).join()

        gevent.joinall([
            gevent.spawn(self.runplugin, '1'),
            gevent.spawn(self.runplugin, '2'),
            gevent.spawn(self.runplugin, '3'),
            gevent.spawn(self.runplugin, '4'),
            gevent.spawn(self.runplugin, '5'),
            gevent.spawn(self.runplugin, '6'),
            gevent.spawn(self.runplugin, '7'),
            gevent.spawn(self.runplugin, '8'),
            gevent.spawn(self.runplugin, '9'),
            gevent.spawn(self.runplugin, '10'),

        ]) 
開發者ID:cflq3,項目名稱:getcms,代碼行數:24,代碼來源:web_finder.py

示例12: run

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def run(self):
        import gevent
        from gevent import monkey
        monkey.patch_all()
        from gevent import pool
        # default 200
        # g_pool = pool.Pool(200)
        g_pool = pool.Pool(self.coroutine)
        tasks = [g_pool.spawn(self.gen_traffic, url) for url in self.url_list]
        gevent.joinall(tasks)
        traffic_list = []
        for i in tasks:
            if i.value is not None:
                traffic_list.append(i.value)
        # save traffic for rescan
        Engine.save_traffic(traffic_list, self.id) 
開發者ID:lwzSoviet,項目名稱:NoXss,代碼行數:18,代碼來源:engine.py

示例13: verify_async

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def verify_async(case_list,coroutine):
        """
        Verify used gevent lib
        :param case_list:
        :param coroutine:
        :return:
        """
        from gevent import monkey
        monkey.patch_all()
        result = []
        geventPool = pool.Pool(coroutine)
        tasks = [geventPool.spawn(Verify.request_and_verify, case) for case in case_list]
        gevent.joinall(tasks)
        for i in tasks:
            if i.value is not None:
                result.append(i.value)
        print_info('Total Verify-Case is: %s, %s error happened.' % (len(case_list), Verify.ERROR_COUNT))
        return result 
開發者ID:lwzSoviet,項目名稱:NoXss,代碼行數:20,代碼來源:engine.py

示例14: join_all_consumer_shedual_task_thread

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def join_all_consumer_shedual_task_thread(cls):
        nb_print(
            (cls.schedulal_thread_to_be_join, len(cls.schedulal_thread_to_be_join), '模式:', cls.global_concurrent_mode))
        if cls.schedual_task_always_use_thread:
            for t in cls.schedulal_thread_to_be_join:
                nb_print(t)
                t.join()
        else:
            if cls.global_concurrent_mode == 1:
                for t in cls.schedulal_thread_to_be_join:
                    nb_print(t)
                    t.join()
            elif cls.global_concurrent_mode == 2:
                # cls.logger.info()
                nb_print(cls.schedulal_thread_to_be_join)
                gevent.joinall(cls.schedulal_thread_to_be_join, raise_error=True, )
            elif cls.global_concurrent_mode == 3:
                for g in cls.schedulal_thread_to_be_join:
                    # eventlet.greenthread.GreenThread.
                    nb_print(g)
                    g.wait() 
開發者ID:ydf0509,項目名稱:distributed_framework,代碼行數:23,代碼來源:base_consumer.py

示例15: _get_total_users

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import joinall [as 別名]
def _get_total_users(trending_problems,
                     start_date,
                     end_date):

    def _perform_query(problem, start_date):
        sql = """
                 SELECT COUNT(id)
                 FROM `submission`
                 WHERE ((problem_link = '%s')
                   AND  (time_stamp >= '%s'))
                 GROUP BY user_id, custom_user_id
              """ % (problem["submission"]["problem_link"],
                     start_date)
        res = db.executesql(sql)
        problem["unique"] = len(res)

    threads = []
    for problem in trending_problems:
        threads.append(gevent.spawn(_perform_query, problem, start_date))

    gevent.joinall(threads)

    return trending_problems

# ---------------------------------------------------------------------------- 
開發者ID:stopstalk,項目名稱:stopstalk-deployment,代碼行數:27,代碼來源:update-trending.py


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