美文网首页
异步corountine

异步corountine

作者: zzjack | 来源:发表于2017-10-25 09:30 被阅读0次

示例

结合一下nodejs的async和golang的goroutine,python的真的很简单。

import threading
import asyncio
import time

async def hello():
    print('Hello world! (%s)' % threading.currentThread())
    await test()
    print('Hello again! (%s)' % threading.currentThread())

async def test():
    time.sleep(2)

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    tasks = [hello()]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()

相关文章

网友评论

      本文标题:异步corountine

      本文链接:https://www.haomeiwen.com/subject/jzgfpxtx.html