Skip to content

Commit

Permalink
Live: do not fail if statistic refresh is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
titodalcanton committed Aug 1, 2024
1 parent 63c0ecf commit 1be8353
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pycbc/events/coinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import numpy
import logging
import copy
from datetime import datetime as dt
import time as timemod
import threading

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 1be8353

Please sign in to comment.