Created
June 20, 2019 18:33
-
-
Save ralexstokes/501d9c65382d91a99670a215c0cb3457 to your computer and use it in GitHub Desktop.
basic trio example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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