美文网首页
异步请求

异步请求

作者: barriers | 来源:发表于2019-12-26 20:28 被阅读0次

先安装nest_asyncio

pip install nest_asyncio

import asyncio
from aiohttp import ClientSession
import time
import nest_asyncio

nest_asyncio.apply()

async def hello():
    url = 'https://www.jianshu.com/u'
    data = {'slength':1.0,'swidth':1.0}
    async with ClientSession() as session:
        async with session.post(url=url,json=data) as response:
            response = await response.read()
    return response

#设置并发数量
tasks = [asyncio.ensure_future(hello()) for _ in range(1000)]
start = time.clock()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(tasks))
end = time.clock()
print('耗时%d秒' %(end-start))

相关文章

  • OKHTTP

    OKHTTP 引用 权限配置 测试URL 同步请求 异步请求 异步get请求 异步测试post请求 Retrofi...

  • AFN异步单任务请求和异步多任务请求

    此处介绍AFNetingWorking 异步单任务请求和异步多任务请求的两种方式。 为什么要使用异步请求 异步请求...

  • Okhttp3

    简介 配置 请求思路 get请求思路 post请求思路 get,post 同步和异步请求 异步请求(get) 同步...

  • 1.2 网络请求-异步请求

    网络请求-异步请求

  • 基于Spring框架实现异步请求与异步调用

    一、异步请求 1.1 同步请求与异步请求 首先看一下同步请求的线程执行模型: 接着看一下异步请求的线程执行模型: ...

  • okhttp分析

    okhttp使用分为同步请求和异步请求:异步请求: request是一个请求对像,包含了请求url,methord...

  • 网络协议

    网络请求分为4类:GET同步请求GET异步请求POST同步请求POST异步请求 同步网络请求步骤: 1:创建网址字...

  • iOS原生网络请求-"连接"与"会

    1.NSURLConnection 1.1 get 异步请求 1.2 post 异步请求 1.3 post 同步请...

  • IntentService和HandlerThread

    IntentService 概述 处理异步请求的Service 客户端使用startService()发送异步请求...

  • Future函数使用

    Future常用方法: 多个网络请求同时进行: await、async模拟异步网路请求: Future模拟异步网络请求:

网友评论

      本文标题:异步请求

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