asyncio 模塊官網(wǎng)連接:https://docs.python.org/zh-cn/3.7/library/asyncio.html
同步原語參考鏈接:https://mozillazg.com/2017/08/python-asyncio-note-synchronization-primitives.html
異步參考:http://python.jobbole.com/88291/
http://python.jobbole.com/87310/
http://python.jobbole.com/87541/
asyncio.gather
?and?
asyncio.wait
?的區(qū)別:https://stackoverflow.com/questions/42231161/asyncio-gather-vs-asyncio-wait
aiohttp官網(wǎng):https://aiohttp.readthedocs.io/en/stable/
aiohttp github:https://github.com/aio-libs/aiohttp
?
asyncio 系列一、asyncio 的協(xié)程與任務(wù):
? ? ? ?https://blog.csdn.net/duxin_csdn/article/details/90517462
?
asyncio 系列二、asyncio 子進(jìn)程:
? ? ? ??https://blog.csdn.net/duxin_csdn/article/details/90517648
?
asyncio 系列三、asyncio 隊列
? ? ? ??https://blog.csdn.net/duxin_csdn/article/details/90517781
?
asyncio 系列四、asyncio 的異常
? ? ? ??https://blog.csdn.net/duxin_csdn/article/details/90517884
?
asyncio 系列四、期程 — asyncio.Future
? ? ? ??https://blog.csdn.net/duxin_csdn/article/details/90518231
?
asyncio 系列五、同步原語—Synchronization Primitives
? ? ? ??https://blog.csdn.net/duxin_csdn/article/details/90518304
?
此外,asyncio還可以創(chuàng)建一個tcp、udp的服務(wù)器模型,參見官網(wǎng)連接:https://docs.python.org/zh-cn/3.7/library/asyncio-stream.html
?
創(chuàng)建http協(xié)議的服務(wù)器模型的話,需要aiohttp模塊,參見aiohttp官網(wǎng):https://aiohttp.readthedocs.io/en/stable/
官網(wǎng)例子:
服務(wù)端:
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
web.run_app(app)
客戶端:
import aiohttp
import asyncio
async def fetch(session, url):
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())
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
