當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。