1 Star 5 Fork 3

Paul / asyncio_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1.4_async.py 595 Bytes
一键复制 编辑 原始数据 按行查看 历史
Paul 提交于 2020-06-26 01:33 . 首次提交
# -*- encoding: utf-8 -*-
"""
@Time : 2020/6/25
@Author : hongboli
"""
import asyncio
async def func1():
print(1)
await asyncio.sleep(2) # 遇到IO耗时操作,比如说网络IO请求等,自动化切换到tasks中的其他任务
print(2)
async def func2():
print(3)
await asyncio.sleep(2) # 遇到IO耗时操作,比如说网络IO请求等,自动化切换到tasks中的其他任务
print(4)
tasks = [
asyncio.ensure_future(func1()),
asyncio.ensure_future(func2())
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
Python
1
https://gitee.com/paultest/asyncio_demo.git
git@gitee.com:paultest/asyncio_demo.git
paultest
asyncio_demo
asyncio_demo
master

搜索帮助