1 Star 5 Fork 3

Paul / asyncio_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
5.2_mysql2.py 919 Bytes
一键复制 编辑 原始数据 按行查看 历史
# -*- encoding: utf-8 -*-
"""
@Time : 2020/7/12
@Author : hongboli
"""
import asyncio
import aiomysql
async def execute(host, password):
print("开始", host)
# 网络IO操作:先去连接 127.0.0.1,遇到IO则自动切换任务,去连接另一个127.0.0.1
conn = await aiomysql.connect(host=host, port=3306, user='root', password=password, db='mysql')
# 网络IO操作:遇到IO会自动切换任务
cur = await conn.cursor()
# 网络IO操作:遇到IO会自动切换任务
await cur.execute("SELECT Host,User FROM user")
# 网络IO操作:遇到IO会自动切换任务
result = await cur.fetchall()
print(result)
# 网络IO操作:遇到IO会自动切换任务
await cur.close()
conn.close()
print("结束", host)
task_list = [
execute('127.0.0.1', "123456"),
execute('127.0.0.1', "123456")
]
asyncio.run(asyncio.wait(task_list))
Python
1
https://gitee.com/paultest/asyncio_demo.git
git@gitee.com:paultest/asyncio_demo.git
paultest
asyncio_demo
asyncio_demo
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891