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


Python asyncio.set_event_loop方法代碼示例

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


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

示例1: parse_arguments

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def parse_arguments():
    """Parse the arguments"""
    parser = argparse.ArgumentParser()
    parser.add_argument("--setup", "-s", action="store_true")
    parser.add_argument("--phone", "-p", action="append")
    parser.add_argument("--token", "-t", action="append", dest="tokens")
    parser.add_argument("--heroku", action="store_true")
    parser.add_argument("--local-db", dest="local", action="store_true")
    parser.add_argument("--web-only", dest="web_only", action="store_true")
    parser.add_argument("--no-web", dest="web", action="store_false")
    parser.add_argument("--heroku-web-internal", dest="heroku_web_internal", action="store_true",
                        help="This is for internal use only. If you use it, things will go wrong.")
    arguments = parser.parse_args()
    logging.debug(arguments)
    if sys.platform == "win32":
        # Subprocess support; not needed in 3.8 but not harmful
        asyncio.set_event_loop(asyncio.ProactorEventLoop())

    return arguments 
開發者ID:friendly-telegram,項目名稱:friendly-telegram,代碼行數:21,代碼來源:main.py

示例2: listen_message_stream

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def listen_message_stream(self, id_blacklist=None):
        id_blacklist = set(id_blacklist or [self.me, ])

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        with aiohttp.ClientSession(loop=loop) as session:
            self.aioclient_session = session

            tasks = [
                asyncio.ensure_future(self.fetch(session, room, id_blacklist))
                for room in self.rooms
            ]
            done, _ = loop.run_until_complete(
                asyncio.wait(tasks, return_when=asyncio.FIRST_EXCEPTION)
            )
            for d in done:
                if d.exception():
                    raise d.exception() 
開發者ID:tuna,項目名稱:fishroom,代碼行數:20,代碼來源:gitter.py

示例3: test_logo_base

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def test_logo_base(app, caplog):
    server = app.create_server(
        debug=True, return_asyncio_server=True, port=PORT
    )
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop._stopping = False

    with caplog.at_level(logging.DEBUG):
        _server = loop.run_until_complete(server)

    _server.close()
    loop.run_until_complete(_server.wait_closed())
    app.stop()

    assert caplog.record_tuples[ROW][1] == logging.DEBUG
    assert caplog.record_tuples[ROW][2] == BASE_LOGO 
開發者ID:huge-success,項目名稱:sanic,代碼行數:19,代碼來源:test_logo.py

示例4: test_logo_false

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def test_logo_false(app, caplog):
    app.config.LOGO = False

    server = app.create_server(
        debug=True, return_asyncio_server=True, port=PORT
    )
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop._stopping = False

    with caplog.at_level(logging.DEBUG):
        _server = loop.run_until_complete(server)

    _server.close()
    loop.run_until_complete(_server.wait_closed())
    app.stop()

    banner, port = caplog.record_tuples[ROW][2].rsplit(":", 1)
    assert caplog.record_tuples[ROW][1] == logging.INFO
    assert banner == "Goin' Fast @ http://127.0.0.1"
    assert int(port) > 0 
開發者ID:huge-success,項目名稱:sanic,代碼行數:23,代碼來源:test_logo.py

示例5: test_logo_true

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def test_logo_true(app, caplog):
    app.config.LOGO = True

    server = app.create_server(
        debug=True, return_asyncio_server=True, port=PORT
    )
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop._stopping = False

    with caplog.at_level(logging.DEBUG):
        _server = loop.run_until_complete(server)

    _server.close()
    loop.run_until_complete(_server.wait_closed())
    app.stop()

    assert caplog.record_tuples[ROW][1] == logging.DEBUG
    assert caplog.record_tuples[ROW][2] == BASE_LOGO 
開發者ID:huge-success,項目名稱:sanic,代碼行數:21,代碼來源:test_logo.py

示例6: test_logo_custom

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def test_logo_custom(app, caplog):
    app.config.LOGO = "My Custom Logo"

    server = app.create_server(
        debug=True, return_asyncio_server=True, port=PORT
    )
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop._stopping = False

    with caplog.at_level(logging.DEBUG):
        _server = loop.run_until_complete(server)

    _server.close()
    loop.run_until_complete(_server.wait_closed())
    app.stop()

    assert caplog.record_tuples[ROW][1] == logging.DEBUG
    assert caplog.record_tuples[ROW][2] == "My Custom Logo" 
開發者ID:huge-success,項目名稱:sanic,代碼行數:21,代碼來源:test_logo.py

示例7: test_keep_alive_timeout_reuse

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def test_keep_alive_timeout_reuse():
    """If the server keep-alive timeout and client keep-alive timeout are
     both longer than the delay, the client _and_ server will successfully
     reuse the existing connection."""
    try:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        client = ReuseableSanicTestClient(keep_alive_timeout_app_reuse, loop)
        headers = {"Connection": "keep-alive"}
        request, response = client.get("/1", headers=headers)
        assert response.status == 200
        assert response.text == "OK"
        loop.run_until_complete(aio_sleep(1))
        request, response = client.get("/1")
        assert response.status == 200
        assert response.text == "OK"
    finally:
        client.kill_server() 
開發者ID:huge-success,項目名稱:sanic,代碼行數:20,代碼來源:test_keep_alive_timeout.py

示例8: loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def loop():
    """Creates new event loop."""
    loop = asyncio.new_event_loop()
    if sys.version_info < (3, 8):
        asyncio.set_event_loop(loop)

    try:
        yield loop
    finally:
        if hasattr(loop, 'is_closed'):
            closed = loop.is_closed()
        else:
            closed = loop._closed   # XXX
        if not closed:
            loop.call_soon(loop.stop)
            loop.run_forever()
            loop.close() 
開發者ID:aio-libs,項目名稱:aioredis,代碼行數:19,代碼來源:conftest.py

示例9: run_via_asyncio

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def run_via_asyncio(async_to_run, debug_event_loop=False):
    logger = logging.getLogger('asyncio.main')

    asyncio.set_event_loop(asyncio.new_event_loop())
    event_loop = asyncio.get_event_loop()
    event_loop.set_debug(enabled=debug_event_loop)
    try:
        logger.info("starting events loop ...")
        event_loop.run_until_complete(async_to_run)

        _cleanup_remaining_tasks(loop=event_loop, logger=logger)

    finally:
        logger.info("closing events loop ...")
        event_loop.close()
        logger.info("... events loop closed") 
開發者ID:nokia,項目名稱:moler,代碼行數:18,代碼來源:asyncio_common.py

示例10: run_via_asyncio

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def run_via_asyncio(async_to_run, debug_event_loop=False):
    logger = logging.getLogger('asyncio.main')

    asyncio.set_event_loop(asyncio.new_event_loop())
    event_loop = asyncio.get_event_loop()
    event_loop.set_debug(enabled=debug_event_loop)
    try:
        logger.info("starting events loop ...")
        event_loop.run_until_complete(async_to_run)

        _cleanup_remaining_tasks(loop=event_loop, logger=logger)

    finally:
        logger.info("closing events loop ...")
        event_loop.close()
        logger.info("... events loop closed")


# configure library directly from dict 
開發者ID:nokia,項目名稱:moler,代碼行數:21,代碼來源:unix_ls_on_device_async.py

示例11: async_test

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def async_test(func):
    @functools.wraps(func)
    def _async_test(*args, **kw):
        cofunc = asyncio.coroutine(func)
        oldloop = asyncio.get_event_loop()
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        loop.set_debug(True)
        console = SharedConsole(interval=0)
        results = SharedCounters(
            "WORKER", "REACHED", "RATIO", "OK", "FAILED", "MINUTE_OK", "MINUTE_FAILED"
        )
        kw["loop"] = loop
        kw["console"] = console
        kw["results"] = results
        try:
            loop.run_until_complete(cofunc(*args, **kw))
        finally:
            loop.stop()
            loop.close()
            asyncio.set_event_loop(oldloop)

    return _async_test 
開發者ID:loads,項目名稱:molotov,代碼行數:25,代碼來源:support.py

示例12: dedicatedloop_noclose

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def dedicatedloop_noclose(func):
    @functools.wraps(func)
    def _loop(*args, **kw):
        old_loop = asyncio.get_event_loop()
        loop = asyncio.new_event_loop()
        loop.set_debug(True)
        loop._close = loop.close
        loop.close = lambda: None
        asyncio.set_event_loop(loop)
        try:
            return func(*args, **kw)
        finally:
            loop._close()
            asyncio.set_event_loop(old_loop)

    return _loop 
開發者ID:loads,項目名稱:molotov,代碼行數:18,代碼來源:support.py

示例13: ad_hoc

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def ad_hoc() -> None:
    try:
        event_loop = asyncio.get_event_loop()
    except RuntimeError:
        event_loop = asyncio.new_event_loop()
        asyncio.set_event_loop(event_loop)

    league.set_status(league.Status.CLOSED)
    multiverse.init() # New Cards?
    event_loop.run_until_complete(multiverse.set_legal_cards_async()) # PD current list
    event_loop.run_until_complete(multiverse.update_pd_legality_async()) # PD previous lists
    insert_seasons.run() # Make sure Season table is up to date
    if redis.REDIS: # Clear the redis cache
        redis.REDIS.flushdb()
    league_end = league.active_league().end_date
    diff = league_end - dtutil.now()
    if diff.days > 0:
        league.set_status(league.Status.OPEN)
    print('Open the gates here')
    reprime_cache.run() # Update deck legalities
    if redis.REDIS: # Clear the redis cache
        redis.REDIS.flushdb() 
開發者ID:PennyDreadfulMTG,項目名稱:Penny-Dreadful-Tools,代碼行數:24,代碼來源:post_rotation.py

示例14: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def main():
    logger.info('VLC Scheduler v%s started.' % version.VERSION)
    
    if sys.platform == 'win32':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    
    loop = asyncio.get_event_loop()
    
    try:
        loop.run_until_complete(main_coro())
    except Exception as e:
        if config.DEBUG:
            logger.fatal(traceback.format_exc())
        else:
            logger.fatal(str(e))
    finally:
        loop.close()
        logger.info('VLC Scheduler stopped.') 
開發者ID:EugeneDae,項目名稱:VLC-Scheduler,代碼行數:21,代碼來源:vlcscheduler.py

示例15: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import set_event_loop [as 別名]
def setUp(self):
        setup_mock_web_api_server(self)

        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        task = asyncio.ensure_future(self.mock_server(), loop=self.loop)
        self.loop.run_until_complete(asyncio.wait_for(task, 0.1))

        self.client = slack.RTMClient(
            token="xoxb-valid",
            base_url="http://localhost:8765",
            auto_reconnect=False,
            run_async=False,
        )
        self.client._web_client = slack.WebClient(
            token="xoxb-valid",
            base_url="http://localhost:8888",
            run_async=False,
        ) 
開發者ID:slackapi,項目名稱:python-slackclient,代碼行數:21,代碼來源:test_rtm_client_functional.py


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