From 06d45c4e1a491abe632fa09da79422359bbaeade Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 9 Jan 2022 21:59:18 -0800 Subject: [PATCH] Improve use of last_refresh + rate wait. --- frontends/ycdl_flask/backend/common.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontends/ycdl_flask/backend/common.py b/frontends/ycdl_flask/backend/common.py index f169e61..70fe749 100644 --- a/frontends/ycdl_flask/backend/common.py +++ b/frontends/ycdl_flask/backend/common.py @@ -76,16 +76,19 @@ def init_ycdldb(*args, **kwargs): def refresher_thread(rate): global last_refresh while True: - next_refresh = last_refresh + rate - wait = next_refresh - time.time() - if wait > 0: + # If the user pressed the refresh button, the thread will wake from + # sleep and find that it should go back to sleep for a little longer. + while True: + next_refresh = last_refresh + rate + wait = next_refresh - time.time() + if wait <= 0: + break time.sleep(wait) - continue + log.info('Starting refresh job.') - thread_kwargs = {'force': False, 'skip_failures': True} refresh_job = threading.Thread( target=ycdldb.refresh_all_channels, - kwargs=thread_kwargs, + kwargs={'force': False, 'skip_failures': True}, daemon=True, ) refresh_job.start()