Skip to content

Commit

Permalink
refactor: rename test_entrypoint.py to main.py and refactor loop …
Browse files Browse the repository at this point in the history
…to handle `KeyboardInterrupt`

- also delete `test_csv.py`
  • Loading branch information
furkan-bilgin committed Oct 11, 2024
1 parent c3c6535 commit a13678f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
22 changes: 17 additions & 5 deletions src/test_entrypoint.py → src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import coloredlogs

from daq.daq_job import load_daq_jobs, parse_store_config, start_daq_job, start_daq_jobs
from daq.models import DAQJobMessageStop

Check failure on line 8 in src/main.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

src/main.py:8:24: F401 `daq.models.DAQJobMessageStop` imported but unused
from daq.store.base import DAQJobStore
from daq.store.models import DAQJobMessageStore

Expand All @@ -13,17 +14,18 @@
datefmt="%Y-%m-%d %H:%M:%S",
)

DAQ_SUPERVISOR_SLEEP_TIME = 0.5
DAQ_JOB_QUEUE_ACTION_TIMEOUT = 0.1

daq_jobs = load_daq_jobs("configs/")
daq_job_threads = start_daq_jobs(daq_jobs)

store_jobs = [x for x in daq_jobs if isinstance(x, DAQJobStore)]

if len(store_jobs) == 0:
if not any(x for x in daq_jobs if isinstance(x, DAQJobStore)):
logging.warning("No store job found, data will not be stored")

while True:

def loop():
global daq_job_threads
dead_threads = [t for t in daq_job_threads if not t.thread.is_alive()]
# Clean up dead threads
daq_job_threads = [t for t in daq_job_threads if t not in dead_threads]
Expand Down Expand Up @@ -64,4 +66,14 @@

daq_job.message_in.put(message, timeout=DAQ_JOB_QUEUE_ACTION_TIMEOUT)

time.sleep(1)
time.sleep(DAQ_SUPERVISOR_SLEEP_TIME)


while True:
try:
loop()
except KeyboardInterrupt:
logging.warning("KeyboardInterrupt received, cleaning up")
for daq_job_thread in daq_job_threads:
daq_job_thread.daq_job.__del__()
break
32 changes: 0 additions & 32 deletions src/test_csv.py

This file was deleted.

0 comments on commit a13678f

Please sign in to comment.