import asyncio
import aiomysql


async def async_ope_mysql():
    sql_conn = await aiomysql.connect(host="", user="xx", password="!xx",
                 db="xx", port=3306)
    cur = await sql_conn.cursor()
    sql = "select Host, User from user;"
    await cur.execute(sql)
    u = await cur.fetchall()
    print(u)
    await cur.close()
    sql_conn.close()

async def main():
    tasks = [
        asyncio.ensure_future(async_ope_mysql()),
        asyncio.ensure_future(async_ope_mysql())
    ]
    await asyncio.wait(tasks)

if __name__ == '__main__':
    p = asyncio.get_event_loop()
    p.run_until_complete(main())

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐