import asyncio
import time
async def get_html(url):
print("start get url")
await asyncio.sleep(2) # 不能使用time.sleep(),这样的话是同步,就不是异步;await就相当于yield from
print("end get url") if __name__ == "__main__":
start_time = time.time()
loop = asyncio.get_event_loop()
tasks = [get_html("http://www.imooc.com") for i in range(10)]
  loop.run_until_complete(asyncio.wait(tasks)) #loop.run_until_complete将task放到loop中,进行事件循环, 这里必须传入的是一个list
print(time.time()-start_time)

最新文章

  1. Win环境下的文件读写
  2. tomcat并发
  3. [转]ANDROID L——Material Design详解(动画篇)
  4. php大力力 [015节]兄弟连高洛峰php教程(土豆网栏目地址)
  5. iOS平台网络类型检测
  6. centos7启动时出现“无法应用原保存的显示器配置”
  7. golang make the first character in a string lowercase/uppercase
  8. ngrok首页、文档和下载 - Web服务安全通道 - 开源中国社区
  9. DLL编写教程(绝对经典之作)
  10. mysql中的unix_timestamp函数
  11. aspnet5备忘
  12. Sql日期时间格式转换大全
  13. 从Unity中的Attribute到AOP(一)
  14. 用NPOI导出Excel,生成下拉列表、以及下拉联动列表(第1篇/共3篇)
  15. python_tornado_session用户验证
  16. vue2.0+ 从插件开发到npm发布
  17. Session&&cookie
  18. linux 测试 get 请求 跳过SSL证书验证
  19. 我来科普一下为毛很多人升级了20M的电信光纤宽带反而感觉速度更卡了
  20. Eclipse:The superclass javax.servlet.http.HttpServlet was not found on the Java Build Path

热门文章

  1. Django JsonResponse 不自动设置 cookie 的解决方案
  2. SQL server已经设置为单用户模式,还是无法做分离、属性设置等操作
  3. NSURLSession的文件下载
  4. Python—日志模块(logging)和网络模块
  5. [日常] 跨语言的POST请求问题的解决
  6. springboot 使用 jedis 连接 Redis 数据库
  7. Incorrect datetime value: '' for column 'examDate' at row 1
  8. python+requests+re匹配抓取猫眼上映电影信息
  9. CSS自定义字体的实现,前端实现字体压缩
  10. scrapy爬虫具体案例详细分析