Skip to content

Commit

Permalink
Same fixes for singles
Browse files Browse the repository at this point in the history
  • Loading branch information
titodalcanton committed Aug 1, 2024
1 parent 3f3ce53 commit 43c7a18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
8 changes: 3 additions & 5 deletions pycbc/events/coinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ def refresh_statistic(self):
self.time_stat_refreshed = timemod.time()
logger.info(
"Checking %s statistic for updated files",
''.join(self.ifos),
ppdets(self.ifos, "-"),
)
with self.stat_calculator_lock:
self.stat_calculator.check_update_files()
Expand All @@ -1441,12 +1441,10 @@ def refresh_statistic(self):
since_stat_refresh = timemod.time() - self.time_stat_refreshed
logger.debug(
"%s statistic: Waiting %.3fs for next refresh",
''.join(self.ifos),
ppdets(self.ifos, "-"),
self.statistic_refresh_rate - since_stat_refresh,
)
timemod.sleep(
self.statistic_refresh_rate - since_stat_refresh + 1
)
timemod.sleep(self.statistic_refresh_rate - since_stat_refresh + 1)


__all__ = [
Expand Down
24 changes: 11 additions & 13 deletions pycbc/events/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import copy
import threading
from datetime import datetime as dt
import time
import numpy as np

Expand Down Expand Up @@ -76,7 +75,7 @@ class (in seconds), default not do do this
self.fixed_ifar = fixed_ifar
self.maximum_ifar = maximum_ifar

self.time_stat_refreshed = dt.now()
self.time_stat_refreshed = time.time()
self.stat_calculator_lock = threading.Lock()
self.statistic_refresh_rate = statistic_refresh_rate

Expand Down Expand Up @@ -360,9 +359,13 @@ def start_refresh_thread(self):
"""
Start a thread managing whether the stat_calculator will be updated
"""
if self.statistic_refresh_rate is None:
logger.info("Statistic refresh disabled for %s", self.ifo)
return
thread = threading.Thread(
target=self.refresh_statistic,
daemon=True
daemon=True,
name="Stat refresh " + self.ifo
)
logger.info("Starting %s statistic refresh thread", self.ifo)
thread.start()
Expand All @@ -373,26 +376,21 @@ 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 = time.time() - self.time_stat_refreshed
if since_stat_refresh > self.statistic_refresh_rate:
self.time_stat_refreshed = dt.now()
self.time_stat_refreshed = time.time()
logger.info(
"Checking %s statistic for updated files",
self.ifo,
"Checking %s statistic for updated files", self.ifo
)
with self.stat_calculator_lock:
self.stat_calculator.check_update_files()
# Sleep one second for safety
time.sleep(1)
# Now use the time it took the check / update the statistic
since_stat_refresh = \
(dt.now() - self.time_stat_refreshed).total_seconds()
since_stat_refresh = time.time() - self.time_stat_refreshed
logger.debug(
"%s statistic: Waiting %.3fs for next refresh",
self.ifo,
self.statistic_refresh_rate - since_stat_refresh
)
time.sleep(
self.statistic_refresh_rate - since_stat_refresh
)
time.sleep(self.statistic_refresh_rate - since_stat_refresh)

0 comments on commit 43c7a18

Please sign in to comment.