asyncio标准库3 HTTP client example
import aiohttp
import asyncio
import async_timeout
async def fetch(session, url):
async with async_timeout.timeout(10):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'http://python.org')
print(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio标准库3 HTTP client example的更多相关文章
- python协程(yield、asyncio标准库、gevent第三方)、异步的实现
引言 同步:不同程序单元为了完成某个任务,在执行过程中需靠某种通信方式以协调一致,称这些程序单元是同步执行的. 例如购物系统中更新商品库存,需要用"行锁"作为通信信号,让不同的更新 ...
- asyncio标准库5 TCP echo client and server
server import asyncio async def handle_echo(reader, writer): data = await reader.read(100) message = ...
- asyncio标准库7 Producer/consumer
使用asyncio.Queue import asyncio import random async def produce(queue, n): for x in range(1, n + 1): ...
- asyncio标准库6 Threads & Subprocess
Threads import asyncio def compute_pi(digits): # implementation return 3.14 async def main(loop): di ...
- asyncio标准库4 asyncio performance
性能包括2部分 每秒并发请求数(Number of concurrent requests per second) 每秒请求负载(Request latency in seconds: min/ave ...
- asyncio标准库2 Hello Clock
如何调度协程,并发运行 asyncio.gather方法可以聚合协程or future def gather(*coros_or_futures, loop=None, return_exceptio ...
- asyncio标准库1 Hello World
利用asyncio的event loop,编写和调度协程 coroutine [,kəuru:'ti:n] n. 协程 Simple coroutine(调用1个协程) import asyncio ...
- Python 标准库一览(Python进阶学习)
转自:http://blog.csdn.net/jurbo/article/details/52334345 写这个的起因是,还是因为在做Python challenge的时候,有的时候想解决问题,连 ...
- Python中级 —— 07标准库
标准库学习 1. The Python Standard Library[https://docs.python.org/3.5/library/] ( 3.5.5 Documentation ) 1 ...
随机推荐
- Largest Submatrix of All 1’s(思维+单调栈)
Given a m-by-n (0,1)-matrix, of all its submatrices of all 1's which is the largest? By largest we m ...
- 基于 bootstrap html 响应式 布局
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...
- Codeforces - 617E 年轻人的第一道莫队
我对莫队算法最为纠结的地方就是区间端点处,应该是像代码里那样理解吧 cnt[i]表示i出现的次数 maxn开2e6比较保险 /*H E A D*/ struct Query{ int l,r,id; ...
- 用淘宝镜像安装electron的方法
在网友那里看到的,命令如下,亲测安装electron 1.7.9 成功,关键是几秒钟就搞定了.今天是 11 Dec 2017. ELECTRON_MIRROR=http://npm.taobao.or ...
- Oracle PL/SQL之WITH查询
[转自] http://blog.csdn.net/t0nsha/article/details/6730855 为什么要用WITH? 1. 如果需要在一段复杂查询里多次应用同一个查询,用WITH可实 ...
- 合唱团---DP
https://www.nowcoder.com/practice/661c49118ca241909add3a11c96408c8?tpId=85&tqId=29830&tPage= ...
- phpstorm 2017 关掉变量提示 parameter name hints
配置面板中搜索 hints 路径 Editor > General > Appearance > Show parameter name hits 去掉前面的勾就行了
- html自定义垂直导航菜单
html自定义垂直导航菜单(目前只支持上级+下级两级菜单) 由于工作的需要,昨天花了三个多小时的事件整理了一份关于垂直导航二级菜单,可以通过js配置的方式初始化菜单box(测试环境:chrome 49 ...
- jquery 去除字符串左右空格
/*** 删除左右两端的空格*/String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, '');} 调用方式: v ...
- Java基础19-封装、方法重载、构造方法(构造函数)
1.封装 封装就是把不想或者不该告诉别人的东西隐藏起来,把可以告诉别人的公开 做法:修改属性的访问权限来限制对属性的访问.并为每一个属性创建一对取值方法和赋值方法,用于对这些属性的访问 class D ...