Created
September 9, 2017 07:29
-
-
Save parity3/796144c621dff8f3d27f71cb6f59f744 to your computer and use it in GitHub Desktop.
Explain queue get behavior of other task siblings when cancelling parent nursery
This file contains 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,itertools | |
count = itertools.count() | |
async def q_get(nurs,q,container): | |
container.append(await q.get()) | |
nurs.cancel_scope.cancel() | |
async def q_putall(q1,q2): | |
q1.put_nowait(next(count)) | |
q2.put_nowait(next(count)) | |
async def main_async_q(): | |
open_nursery = trio.open_nursery | |
results = [] | |
q1 = trio.Queue(10) | |
q2 = trio.Queue(10) | |
async with open_nursery() as nurs: | |
nurs.spawn(q_get, nurs, q1, results) | |
nurs.spawn(q_get, nurs, q2, results) | |
nurs.spawn(q_putall,q1,q2) | |
print(f"results (should be 1 in length but actually has BOTH results??): {results}") | |
def main_sync(): | |
run = trio.run | |
run(main_async_q) | |
if __name__ == '__main__': | |
main_sync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment