Skip to content

Commit

Permalink
Switch build monitor to daemon thread
Browse files Browse the repository at this point in the history
  • Loading branch information
piercefreeman committed Apr 30, 2024
1 parent 60b6af7 commit bbec38f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion mountaineer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from traceback import format_exception
from typing import Any, Callable, MutableMapping

from click import secho
from fastapi import Request
from rich.traceback import install as rich_traceback_install

Expand Down
13 changes: 7 additions & 6 deletions mountaineer/watch_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def start(self):
if self.has_started:
raise Exception("WatcherWebservice has already started")

# UvicornThreads are daemon threads by default
self.webservice_thread = UvicornThread(
app=self.app,
port=self.port,
Expand All @@ -80,7 +81,7 @@ def start(self):
LOGGER.debug("Starting WatcherWebservice on port %d", self.port)
self.webservice_thread.start()

self.monitor_build_thread = Thread(target=self.monitor_builds)
self.monitor_build_thread = Thread(target=self.monitor_builds, daemon=True)
self.monitor_build_thread.start()

self.has_started = True
Expand All @@ -93,21 +94,21 @@ def stop(self, wait_for_completion: int = 1) -> bool:
to send a harder termination signal to terminate the threads on the OS level.
"""
success : bool = True
success: bool = True
if self.webservice_thread is not None:
self.webservice_thread.stop()
self.webservice_thread.join(wait_for_completion)
if self.monitor_build_thread is not None:
self.notification_queue.put(None)
self.monitor_build_thread.join(wait_for_completion)

if (
self.webservice_thread and self.webservice_thread.is_alive()
) or (
if (self.webservice_thread and self.webservice_thread.is_alive()) or (
self.monitor_build_thread and self.monitor_build_thread.is_alive()
):
success = False
LOGGER.info(f"WatcherWebservice still has outstanding threads: {self.webservice_thread} {self.monitor_build_thread}")
LOGGER.info(
f"WatcherWebservice still has outstanding threads: {self.webservice_thread} {self.monitor_build_thread}"
)
else:
LOGGER.info("WatcherWebservice has fully stopped")

Expand Down

0 comments on commit bbec38f

Please sign in to comment.