From 1be8353562bc142f437d46e39808ba4110c0969e Mon Sep 17 00:00:00 2001 From: Tito Dal Canton Date: Thu, 1 Aug 2024 13:37:06 +0200 Subject: [PATCH] Live: do not fail if statistic refresh is not used --- pycbc/events/coinc.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pycbc/events/coinc.py b/pycbc/events/coinc.py index 2fcf4a48a30..7a33d6db7de 100644 --- a/pycbc/events/coinc.py +++ b/pycbc/events/coinc.py @@ -28,7 +28,6 @@ import numpy import logging import copy -from datetime import datetime as dt import time as timemod import threading @@ -317,7 +316,7 @@ def win(ifo1, ifo2): # tested against fixed and pivot are now present for testing with new # dependent ifos for ifo2 in ids: - logger.info('added ifo %s, testing against %s' % (ifo1, ifo2)) + logger.info('added ifo %s, testing against %s', ifo1, ifo2) w = win(ifo1, ifo2) left = time1.searchsorted(ctimes[ifo2] - w) right = time1.searchsorted(ctimes[ifo2] + w) @@ -887,7 +886,7 @@ class (in seconds), default not do do this **kwargs ) - self.time_stat_refreshed = dt.now() + self.time_stat_refreshed = timemod.time() self.stat_calculator_lock = threading.Lock() self.statistic_refresh_rate = statistic_refresh_rate @@ -1406,6 +1405,8 @@ def start_refresh_thread(self): """ Start a thread managing whether the stat_calculator will be updated """ + if self.statistic_refresh_rate is None: + return thread = threading.Thread( target=self.refresh_statistic, daemon=True @@ -1422,10 +1423,9 @@ def refresh_statistic(self): """ while True: # How long since the statistic was last updated? - since_stat_refresh = \ - (dt.now() - self.time_stat_refreshed).total_seconds() + since_stat_refresh = timemod.time() - self.time_stat_refreshed if since_stat_refresh > self.statistic_refresh_rate: - self.time_stat_refreshed = dt.now() + self.time_stat_refreshed = timemod.time() logger.info( "Checking %s statistic for updated files", ''.join(self.ifos), @@ -1435,8 +1435,7 @@ def refresh_statistic(self): # Sleep one second for safety timemod.sleep(1) # Now include the time it took the check / update the statistic - since_stat_refresh = \ - (dt.now() - self.time_stat_refreshed).total_seconds() + since_stat_refresh = timemod.time() - self.time_stat_refreshed logger.debug( "%s statistic: Waiting %.3fs for next refresh", ''.join(self.ifos),