Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark watchdog thread daemonic #16

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions oresat_c3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import os
import socket
from threading import Event, Thread
from threading import Thread
import time

from olaf import (
Gpio,
Expand Down Expand Up @@ -59,19 +60,19 @@ def get_hw_id(mock: bool) -> int:
return hw_id


def watchdog(event: Event):
def watchdog():
"""Pet the watchdog app (which pets the watchdog circuit)."""

udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

while not event.is_set():
while True:
failed = 0
for service in app._services: # pylint: disable=W0212
failed += int(service.status == ServiceState.FAILED)
if not app.od["flight_mode"].value or failed == 0:
logger.debug("watchdog pet")
udp_socket.sendto(b"PET", ("localhost", 20001))
event.wait(10)
time.sleep(10)


def main():
Expand All @@ -84,8 +85,7 @@ def main():
mock_hw = len(mock_args) != 0

# start watchdog thread ASAP
event = Event()
thread = Thread(target=watchdog, args=(event,))
thread = Thread(target=watchdog, daemon=True)
thread.start()

app.od["versions"]["sw_version"].value = __version__
Expand All @@ -112,10 +112,6 @@ def main():

olaf_run()

# stop watchdog thread
event.set()
thread.join()


if __name__ == "__main__":
main()
Loading