当前位置: 首页>>代码示例>>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;未经允许,请勿转载。