From 61e9db32297aeadb0301c0b2ccbd0c408ba64462 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 3 May 2022 19:07:32 -0400 Subject: [PATCH] Handle ``iter_dts()`` already exhausted edge case --- piker/data/feed.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/piker/data/feed.py b/piker/data/feed.py index a95b87b4..b877ed65 100644 --- a/piker/data/feed.py +++ b/piker/data/feed.py @@ -407,14 +407,27 @@ async def start_backfill( ) # reset dtrange gen to new start point - next_end = iter_dts_gen.send(start_dt) - log.info( - f'Reset frame index to start at {start_dt}\n' - f'Was at {next_end}' - ) + try: + next_end = iter_dts_gen.send(start_dt) + log.info( + f'Reset frame index to start at {start_dt}\n' + f'Was at {next_end}' + ) + + # NOTE: manually set "earliest end datetime" index-value + # to avoid the request loop getting confused about + # new frames that are earlier in history - i.e. this + # **is not** the case of out-of-order frames from + # an async batch request. + earliest_end_dt = start_dt + + except StopIteration: + # gen already terminated meaning we probably already + # exhausted it via frame requests. + log.info( + f"Datetime index already exhausted, can't reset.." + ) - # TODO: can we avoid this? - earliest_end_dt = start_dt to_push = diff_history( array,