python异步---trio
2018-05-17 本文已影响0人
hugoren
用法
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