diff --git a/piker/clearing/_client.py b/piker/clearing/_client.py index 121cd080..598f4f54 100644 --- a/piker/clearing/_client.py +++ b/piker/clearing/_client.py @@ -191,7 +191,6 @@ async def maybe_open_emsd( yield portal - @asynccontextmanager async def open_ems( broker: str, @@ -248,4 +247,13 @@ async def open_ems( with trio.fail_after(10): await book._ready_to_receive.wait() - yield book, trades_stream + try: + yield book, trades_stream + + finally: + # TODO: we want to eventually keep this up (by having + # the exec loop keep running in the pikerd tree) but for + # now we have to kill the context to avoid backpressure + # build-up on the shm write loop. + with trio.CancelScope(shield=True): + await trades_stream.aclose()