本文整理汇总了Python中asyncio._get_running_loop方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio._get_running_loop方法的具体用法?Python asyncio._get_running_loop怎么用?Python asyncio._get_running_loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块asyncio的用法示例。
在下文中一共展示了asyncio._get_running_loop方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run_main
点赞 6
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import _get_running_loop [as 别名]
def run_main(main):
"""Main entrypoint for asyncio tasks.
This differs from `asyncio.run` in one key way - the main task is cancelled
*first*, then any outstanding tasks are cancelled (and logged, remaining
tasks are indicative of bugs/failures).
"""
if asyncio._get_running_loop() is not None:
raise RuntimeError("Cannot be called from inside a running event loop")
main_task = None
loop = asyncio.new_event_loop()
try:
asyncio.set_event_loop(loop)
main_task = loop.create_task(main)
return loop.run_until_complete(main_task)
finally:
try:
if main_task is not None:
loop.run_until_complete(cancel_task(main_task))
_cancel_all_tasks(loop)
loop.run_until_complete(loop.shutdown_asyncgens())
finally:
asyncio.set_event_loop(None)
loop.close()
开发者ID:dask,项目名称:dask-gateway,代码行数:27,
示例2: test_get_event_loop_returns_running_loop
点赞 6
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import _get_running_loop [as 别名]
def test_get_event_loop_returns_run