From 9b5f052597705e9d29ebae903805f19f769d294b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 3 May 2022 13:52:23 -0400 Subject: [PATCH] Handle no sampler subs case on history broadcasts When the market isn't open the feed layer won't create a subscriber entry in the sampler broadcast loop and so if a manual call to ``broadcast()`` is made (like when trying to update a chart from a history prepend) we need to handle that case and just broadcast a random `-1` for now..BD --- piker/data/_sampling.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/piker/data/_sampling.py b/piker/data/_sampling.py index b5a75a67..8bc677cf 100644 --- a/piker/data/_sampling.py +++ b/piker/data/_sampling.py @@ -146,13 +146,21 @@ async def broadcast( # a given sample period. subs = sampler.subscribers.get(delay_s, ()) + last = -1 + if shm is None: - lowest = min(sampler.ohlcv_shms.keys()) - shm = sampler.ohlcv_shms[lowest][0] + periods = sampler.ohlcv_shms.keys() + # if this is an update triggered by a history update there + # might not actually be any sampling bus setup since there's + # no "live feed" active yet. + if periods: + lowest = min(periods) + shm = sampler.ohlcv_shms[lowest][0] + last = shm._last.value for stream in subs: try: - await stream.send({'index': shm._last.value}) + await stream.send({'index': last}) except ( trio.BrokenResourceError, trio.ClosedResourceError