async和await关键词用于定义原生的协程

#python为了将语义变得更加明确,就引入了async和await关键词用于定义原生的协程
# async def downloader(url):
#     return "xxxx"
import types

@types.coroutine
def downloader(url):
    yield "xxx"

async def download_url(url):
    #dosomethings
    html = await downloader(url)
    return html

if __name__ == "__main__":
    coro = download_url("http://www.imooc.com")
    # next(None)
    coro.send(None)

 

posted @ 2018-04-24 14:31  Erick-LONG  阅读(269)  评论(0编辑  收藏  举报