Skip to content

Instantly share code, notes, and snippets.

@ralexstokes
Created June 20, 2019 18:33
Show Gist options
  • Save ralexstokes/501d9c65382d91a99670a215c0cb3457 to your computer and use it in GitHub Desktop.
Save ralexstokes/501d9c65382d91a99670a215c0cb3457 to your computer and use it in GitHub Desktop.
basic trio example
import trio
async def child1(nursery):
print("from 1")
# will cancel the nursery
# raise Exception("there")
await trio.sleep(1)
print("exit 1")
async def child2(nursery):
print("from 2")
await trio.sleep(1)
print("exit 2")
async def parent():
async with trio.open_nursery() as n:
n.start_soon(child1, n)
n.start_soon(child2, n)
print("done parent")
trio.run(parent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment