美文网首页
python异步---trio

python异步---trio

作者: hugoren | 来源:发表于2018-05-17 14:41 被阅读0次

用法

pip install trio

语法上与curio类似,与asyncio更轻量级

import trio


async def child1():
    print("child1")
    await  trio.sleep(1)
    print("child1 exist")


async def child2():
    print("child2")
    await trio.sleep(1)
    print("child2 exist")


async def parent():
    print("parent")
    async with trio.open_nursery() as nursery:
        print("spawing child1")
        nursery.start_soon(child1)
        print("spawing child2")
        nursery.start_soon(child2)

trio.run(parent)
image.png

参考:
https://trio.readthedocs.io/en/latest/tutorial.html#before-you-begin

相关文章

网友评论

      本文标题:python异步---trio

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