asyncio.run()似乎会阻止我启动的其他进程
创始人
2024-09-21 05:30:32
0

可以使用asyncio.create_task()将其他任务分配给不同的事件循环。例如:

import asyncio

async def main():
    print("Running main")
    await asyncio.sleep(5)
    print("End main")

async def other_task():
    print("Running other task")
    await asyncio.sleep(3)
    print("End other task")

async def start_other_task():
    loop = asyncio.get_running_loop()
    task = loop.create_task(other_task())
    await task

if __name__ == '__main__':
    asyncio.run(main())
    asyncio.run(start_other_task())

在这个例子中,我们定义了两个异步任务main()和other_task(),并使用asyncio.create_task()将other_task()分配给另一个事件循环。然后,在主程序中使用asyncio.run()运行main()任务,而使用start_other_task()函数并使用另一个asyncio.run()运行other_task()任务。这样,我们就可以避免asyncio.run()阻止其他进程启动的问题。

相关内容

热门资讯

透视好牌!aapoker辅助器... 透视好牌!aapoker辅助器怎么用(透视)透视脚本下载(好像有挂)进入游戏-大厅左侧-新手福利-激...
透视能赢!约局吧德州可以透视吗... 透视能赢!约局吧德州可以透视吗(透视)解密教程(2026已更新)(哔哩哔哩)1、玩家可以在约局吧德州...
透视安卓版!aapoker能控... 透视安卓版!aapoker能控制牌吗(透视)透视脚本入口(果然存在有挂)1、完成aapoker能控制...
透视app!epoker透视(... 透视app!epoker透视(透视)透明挂教程(2024已更新)(哔哩哔哩);1、完成epoker透...
透视攻略!aapoker ai... 透视攻略!aapoker ai插件(透视)真的假的(果然真的是有挂);1、首先打开aapoker a...
透视辅助!哈糖大菠萝有挂吗5个... 透视辅助!哈糖大菠萝有挂吗5个常用方法(透视)攻略教程(2026已更新)(哔哩哔哩)1、金币登录送、...
透视有挂!werplan怎么透... 透视有挂!werplan怎么透视(透视)新2025教程(2022已更新)(哔哩哔哩)1、起透看视 w...
透视了解!aapoker公共底... 透视了解!aapoker公共底牌(透视)透视插件(果然真的是有挂)1、操作简单,无需注册,只需要使用...
透视规律!拱趴游戏破解器(透视... 透视规律!拱趴游戏破解器(透视)揭秘教程(2020已更新)(哔哩哔哩)1、完成拱趴游戏破解器透视辅助...
透视工具!aapoker怎么提... 透视工具!aapoker怎么提高中牌率(透视)真的假的(都是是真的有挂)在进入aapoker怎么提高...