Facepalm: join nursery first to avoid channel-closed-too-early

aio_explicit_task_cancels
Tyler Goodlet 2022-04-12 15:03:44 -04:00
parent 90593611bb
commit 333fad8819
1 changed files with 6 additions and 1 deletions

View File

@ -256,8 +256,13 @@ async def stream_from_aio(
if fan_out:
# start second task that get's the same stream value set.
async with (
trio.open_nursery() as n,
# NOTE: this has to come first to avoid
# the channel being closed before the nursery
# tasks are joined..
chan.subscribe() as br,
trio.open_nursery() as n,
):
n.start_soon(consume, br)
await consume(chan)