摘要: #asyncio 没有提供http协议的接口 aiohttp import asyncio import socket from urllib.parse import urlparse async def get_url(url): #通过socket请求html url = urlparse(url) host = url.netloc path = ur... 阅读全文
posted @ 2019-07-21 19:22 下路派出所 阅读(1659) 评论(0) 推荐(1) 编辑
摘要: import asyncio def callback(loop, i): print("success time {} {}".format(i, loop.time())) async def get_html(url): print("start get url") await asyncio.sleep(1) print("end get url") ... 阅读全文
posted @ 2019-07-21 11:23 下路派出所 阅读(3837) 评论(0) 推荐(0) 编辑
摘要: #使用多线程:在协程中集成阻塞io import asyncio from concurrent.futures import ThreadPoolExecutor import socket from urllib.parse import urlparse def get_url(url): #通过socket请求html url = urlparse(url) ... 阅读全文
posted @ 2019-07-21 11:16 下路派出所 阅读(2535) 评论(0) 推荐(0) 编辑
摘要: 1. call_soon, 协程一运行就马上运行 2. call_later 3. call_at 阅读全文
posted @ 2019-07-21 10:55 下路派出所 阅读(1946) 评论(0) 推荐(1) 编辑