# python 为了将语义更加明确, 就引入了async和await关键词用于定义原生的协程
# await 只能出现在 async里面 async里面不能有yield
async def downloader(url):
return '测试'
async def download_url(url):
print(url)
html = await downloader(url) # await 后面接收await对象 await对象实现了__await__方法
return html
if __name__ == '__main__':
res = download_url('https://www.zhijinyu.com')
# next(None) 这样调用会报错 RuntimeWarning: coroutine 'download_url' was never awaited
res.send(None)
网友评论