From 47f823ab2285ac68f93fcc04ed1e9ead7c817b70 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 5 Apr 2021 08:06:28 -0400 Subject: [PATCH] Always close emsd data connection on close --- piker/clearing/_client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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()