当前位置: 首页>>代码示例>>Python>>正文


Python uvloop.new_event_loop方法代码示例

本文整理汇总了Python中uvloop.new_event_loop方法的典型用法代码示例。如果您正苦于以下问题:Python uvloop.new_event_loop方法的具体用法?Python uvloop.new_event_loop怎么用?Python uvloop.new_event_loop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uvloop的用法示例。


在下文中一共展示了uvloop.new_event_loop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def run(coro, loop=None):
    async def main_task():
        pycurl_task = aio.ensure_future(curl_loop())
        try:
            r = await coro
        finally:
            pycurl_task.cancel()
            with suppress(aio.CancelledError):
                await pycurl_task
        return r, pycurl_task

    if loop is None:
        loop = uvloop.new_event_loop()
        # loop = aio.get_event_loop()
    aio.set_event_loop(loop)
    loop.set_exception_handler(exception_handler)
    r, _ = loop.run_until_complete(main_task())
    return r 
开发者ID:pingf,项目名称:falsy,代码行数:20,代码来源:run.py

示例2: pytest_configure

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def pytest_configure(config):
    global LOOP_INIT
    loop_name = config.getoption('--loop')
    factory = {
        "aioloop": asyncio.new_event_loop,
    }
    if uvloop is not None:
        factory["uvloop"] = uvloop.new_event_loop

    if loop_name:
        if loop_name not in factory:
            raise ValueError(
                "{name} is not valid option".format(name=loop_name)
            )
        LOOP_INIT = factory[loop_name]
    else:
        LOOP_INIT = factory["aioloop"] 
开发者ID:yunstanford,项目名称:pytest-sanic,代码行数:19,代码来源:plugin.py

示例3: loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def loop(request, loop_type):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(None)

    if uvloop and loop_type == 'uvloop':
        loop = uvloop.new_event_loop()
    else:
        loop = asyncio.new_event_loop()

    yield loop

    if not loop._closed:
        loop.call_soon(loop.stop)
        loop.run_forever()
        loop.close()
    gc.collect()
    asyncio.set_event_loop(None) 
开发者ID:aio-libs,项目名称:aiomysql,代码行数:19,代码来源:conftest.py

示例4: event_loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def event_loop(self):
        q = asyncio.Queue()
        for request_item in self.request_list:
            q.put_nowait(request_item)
        loop = uvloop.new_event_loop()
        asyncio.set_event_loop(loop)
        tasks = [self.handle_tasks(task_id, q) for task_id in range(self.coroutine_num)]
        loop.run_until_complete(asyncio.wait(tasks))
        loop.close() 
开发者ID:m4yfly,项目名称:butian-src-domains,代码行数:11,代码来源:base.py

示例5: run

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def run():
    asyncio.set_event_loop(uvloop.new_event_loop())
    server = app.create_server(host="0.0.0.0", port=80)
    loop = asyncio.get_event_loop()
    asyncio.ensure_future(server)
    signal(SIGINT, lambda s, f: loop.stop())
    try:
        loop.run_forever()
    except:
        loop.stop() 
开发者ID:Rowl1ng,项目名称:rasa_wechat,代码行数:12,代码来源:manage.py

示例6: loop_context

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def loop_context(loop_factory=asyncio.new_event_loop, fast=False):
    """A contextmanager that creates an event_loop, for test purposes.

    Handles the creation and cleanup of a test loop.
    """
    loop = setup_test_loop(loop_factory)
    yield loop
    teardown_test_loop(loop, fast=fast) 
开发者ID:Eyepea,项目名称:aiosip,代码行数:10,代码来源:pytest_plugin.py

示例7: setup_test_loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def setup_test_loop(loop_factory=asyncio.new_event_loop):
    """Create and return an asyncio.BaseEventLoop instance.

    The caller should also call teardown_test_loop, once they are done
    with the loop.
    """
    loop = loop_factory()
    asyncio.set_event_loop(loop)
    if sys.platform != "win32":
        policy = asyncio.get_event_loop_policy()
        watcher = asyncio.SafeChildWatcher()
        watcher.attach_loop(loop)
        policy.set_child_watcher(watcher)
    return loop 
开发者ID:Eyepea,项目名称:aiosip,代码行数:16,代码来源:pytest_plugin.py

示例8: pytest_configure

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def pytest_configure(config):
    loops = config.getoption('--loop')

    factories = {'pyloop': asyncio.new_event_loop}

    if uvloop is not None:  # pragma: no cover
        factories['uvloop'] = uvloop.new_event_loop

    if tokio is not None:  # pragma: no cover
        factories['tokio'] = tokio.new_event_loop

    LOOP_FACTORIES.clear()
    LOOP_FACTORY_IDS.clear()

    if loops == 'all':
        loops = 'pyloop,uvloop?,tokio?'

    for name in loops.split(','):
        required = not name.endswith('?')
        name = name.strip(' ?')
        if name in factories:
            LOOP_FACTORIES.append(factories[name])
            LOOP_FACTORY_IDS.append(name)
        elif required:
            raise ValueError(
                "Unknown loop '%s', available loops: %s" % (
                    name, list(factories.keys())))
    asyncio.set_event_loop(None) 
开发者ID:Eyepea,项目名称:aiosip,代码行数:30,代码来源:pytest_plugin.py

示例9: publish

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def publish(self, channel_name='ready'):
        signal(SIGINT, interrupt_handler)
        try:
            loop = uvloop.new_event_loop()
            bot = Bot(token=getenv('TELEGRAM_KEY'), loop=loop)
            task = loop.create_task(subscribe_and_listen(bot, channel_name))
            loop.run_until_complete(task)
        finally:
            task.cancel()
            loop.run_until_complete(bot.close())
            loop.close() 
开发者ID:MichaMucha,项目名称:pydata2019-nlp-system,代码行数:13,代码来源:publisher.py

示例10: launch_pubsub_task

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def launch_pubsub_task(func: Callable, 
        source='comments', sink='processed', subprocess=False):
    async def pubsub_func():
        r = redis.Redis(REDIS_HOST)
        async for message in listen(source):
            if message is StopAsyncIteration:
                break
            output = func(message['data'])
            if output is not None:
                await publish(r, sink, output)

    def run_task():
        loop = uvloop.new_event_loop()
        task = loop.create_task(pubsub_func())    
        try:
            loop.run_until_complete(task)
        finally:
            print('Stopping...')
            task.cancel()
            loop.stop()
            loop.close()

    signal(SIGINT, interrupt_handler)

    if subprocess:
        process = Process(target=run_task)
        process.start()
    else:
        run_task() 
开发者ID:MichaMucha,项目名称:pydata2019-nlp-system,代码行数:31,代码来源:pubsub_redis.py

示例11: publish

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def publish(self, channel_name='processed'):
        signal(SIGINT, interrupt_handler)
        try:
            loop = uvloop.new_event_loop()
            bot = Bot(token=getenv('TELEGRAM_KEY'), loop=loop)
            task = loop.create_task(subscribe_and_listen(bot, channel_name))
            loop.run_until_complete(task)
        finally:
            task.cancel()
            loop.run_until_complete(bot.close())
            loop.close() 
开发者ID:MichaMucha,项目名称:pydata2019-nlp-system,代码行数:13,代码来源:publisher.py

示例12: get_event_loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def get_event_loop(self):
        import asyncio
        return asyncio.new_event_loop() 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:5,代码来源:bottle.py

示例13: run

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def run():
    asyncio.set_event_loop(uvloop.new_event_loop())
    server = app.create_server(host="0.0.0.0", port=7777)
    loop = asyncio.get_event_loop()
    asyncio.ensure_future(server)
    signal(SIGINT, lambda s, f: loop.stop())
    try:
        loop.run_forever()
    except:
        loop.stop() 
开发者ID:gusibi,项目名称:Metis,代码行数:12,代码来源:manager.py

示例14: new_event_loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def new_event_loop():
    """Get the fastest loop available.
    """
    try:
        import uvloop
        return uvloop.new_event_loop()
    except ImportError as err:
        utils.log_to_stderr().warn(str(err))
        return asyncio.new_event_loop() 
开发者ID:friends-of-freeswitch,项目名称:switchio,代码行数:11,代码来源:loop.py

示例15: _run_loop

# 需要导入模块: import uvloop [as 别名]
# 或者: from uvloop import new_event_loop [as 别名]
def _run_loop(self, debug):
        self.loop = loop = new_event_loop()
        loop._tid = get_ident()
        # FIXME: causes error with a thread safety check in Future.call_soon()
        # called from Future.add_done_callback() - stdlib needs a patch?
        if debug:
            loop.set_debug(debug)
            logging.getLogger('asyncio').setLevel(logging.DEBUG)
        asyncio.set_event_loop(loop)
        self.loop.run_forever() 
开发者ID:friends-of-freeswitch,项目名称:switchio,代码行数:12,代码来源:loop.py


注:本文中的uvloop.new_event_loop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。