31 lines
969 B
Python
31 lines
969 B
Python
import time
|
|
from threading import Thread
|
|
|
|
class NcursesThreads:
|
|
def __init__(self, alarm_logic):
|
|
self.alarm_logic = alarm_logic
|
|
self.running = True
|
|
|
|
def alarm_check_thread(self):
|
|
"""Thread for continuously checking alarms."""
|
|
while self.running:
|
|
try:
|
|
self.alarm_logic.check_alarms()
|
|
time.sleep(1)
|
|
except Exception as e:
|
|
# Handle any errors during alarm checking
|
|
print(f"Alarm check error: {str(e)}")
|
|
time.sleep(5)
|
|
|
|
def start_threads(self):
|
|
"""Starts the necessary threads for ncurses client."""
|
|
self.alarm_thread = Thread(target=self.alarm_check_thread)
|
|
self.alarm_thread.daemon = True
|
|
self.alarm_thread.start()
|
|
|
|
def stop_threads(self):
|
|
"""Stops all running threads."""
|
|
self.running = False
|
|
if self.alarm_thread.is_alive():
|
|
self.alarm_thread.join()
|