Improve use of last_refresh + rate wait.
This commit is contained in:
parent
8840599be0
commit
06d45c4e1a
1 changed files with 9 additions and 6 deletions
|
@ -75,17 +75,20 @@ def init_ycdldb(*args, **kwargs):
|
||||||
|
|
||||||
def refresher_thread(rate):
|
def refresher_thread(rate):
|
||||||
global last_refresh
|
global last_refresh
|
||||||
|
while True:
|
||||||
|
# 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:
|
while True:
|
||||||
next_refresh = last_refresh + rate
|
next_refresh = last_refresh + rate
|
||||||
wait = next_refresh - time.time()
|
wait = next_refresh - time.time()
|
||||||
if wait > 0:
|
if wait <= 0:
|
||||||
|
break
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
continue
|
|
||||||
log.info('Starting refresh job.')
|
log.info('Starting refresh job.')
|
||||||
thread_kwargs = {'force': False, 'skip_failures': True}
|
|
||||||
refresh_job = threading.Thread(
|
refresh_job = threading.Thread(
|
||||||
target=ycdldb.refresh_all_channels,
|
target=ycdldb.refresh_all_channels,
|
||||||
kwargs=thread_kwargs,
|
kwargs={'force': False, 'skip_failures': True},
|
||||||
daemon=True,
|
daemon=True,
|
||||||
)
|
)
|
||||||
refresh_job.start()
|
refresh_job.start()
|
||||||
|
|
Loading…
Reference in a new issue