美文网首页
python异步并发

python异步并发

作者: 雨田君的记事本 | 来源:发表于2021-10-18 17:36 被阅读0次
    import asyncio
    import random
    import time
    import aiohttp
    from aiohttp import ClientSession
    
    async def login(i):
        async with ClientSession() as session:
            res = await session.post(url="http://10.0.104.48:18010/account/api/login", data={'password': '12345', 'mobile': '13488985003'})
            a = await res.json()
            print(i)
    
    async def main():
        res = await asyncio.gather(*(login(i) for i in range(500)))
        return res
    
    if __name__ == "__main__":
        a = time.time()
        asyncio.run(main())
        print(time.time() - a)
    
    

    相关文章

      网友评论

          本文标题:python异步并发

          本文链接:https://www.haomeiwen.com/subject/fwpnoltx.html