logger = logging.getLogger(__file__)
+@logging_utils.LoggingContext(logger, prefix="janitor:")
def thread_janitor() -> None:
- logging_utils.register_thread_logging_prefix("janitor:")
tracemalloc.start()
tracemalloc_target = 0.0
gc_target = 0.0
return page
+@logging_utils.LoggingContext(logger, prefix="chooser:")
def thread_change_current(command_queue: Queue) -> None:
- logging_utils.register_thread_logging_prefix("chooser:")
page_history = ["", ""]
swap_page_target = 0.0
f.write("</TABLE>")
+@logging_utils.LoggingContext(logger, prefix="renderer:")
def thread_invoke_renderers() -> None:
- logging_utils.register_thread_logging_prefix("renderer:")
render_times: Dict[str, np.array] = {}
render_counts: collections.Counter = collections.Counter()
last_render: Dict[str, datetime] = {}
janitor_thread: Optional[Thread] = None
hotword_thread: Optional[Thread] = None
- logging_utils.register_thread_logging_prefix("watchdog:")
- while True:
- if hotword_thread is None or not hotword_thread.is_alive():
- if hotword_thread is None:
- logger.info("watchdog: Starting up the hotword detector thread...")
- else:
- logger.warning(
- "The hotword detector thread seems to have died; restarting it and hoping for the best."
+ with logging_utils.LoggingContext(logger, prefix="watchdog:"):
+ while True:
+ if hotword_thread is None or not hotword_thread.is_alive():
+ if hotword_thread is None:
+ logger.info("Starting up the hotword detector thread...")
+ else:
+ logger.warning(
+ "The hotword detector thread seems to have died; restarting it and hoping for the best."
+ )
+ keyword_paths = [pvporcupine.KEYWORD_PATHS[x] for x in ["bumblebee"]]
+ sensitivities = [0.7] * len(keyword_paths)
+ listener = listen.HotwordListener(
+ command_queue,
+ keyword_paths,
+ sensitivities,
)
- keyword_paths = [pvporcupine.KEYWORD_PATHS[x] for x in ["bumblebee"]]
- sensitivities = [0.7] * len(keyword_paths)
- listener = listen.HotwordListener(
- command_queue,
- keyword_paths,
- sensitivities,
- )
- hotword_thread = Thread(target=listener.listen_forever, args=())
- hotword_thread.start()
+ hotword_thread = Thread(target=listener.listen_forever, args=())
+ hotword_thread.start()
- if changer_thread is None or not changer_thread.is_alive():
- if changer_thread is None:
- logger.info("Starting up the current page changer thread...")
- else:
- logger.warning(
- "The current page changer thread seems to have died; restarting it and hoping for the best."
+ if changer_thread is None or not changer_thread.is_alive():
+ if changer_thread is None:
+ logger.info("Starting up the current page changer thread...")
+ else:
+ logger.warning(
+ "The current page changer thread seems to have died; restarting it and hoping for the best."
+ )
+ changer_thread = Thread(
+ target=thread_change_current, args=(command_queue,)
)
- changer_thread = Thread(target=thread_change_current, args=(command_queue,))
- changer_thread.start()
+ changer_thread.start()
- if renderer_thread is None or not renderer_thread.is_alive():
- if renderer_thread is None:
- logger.info("Starting up the page renderer thread...")
- else:
- logger.warning(
- "The page renderer thread seems to have died; restarting it and hoping for the best."
- )
- renderer_thread = Thread(target=thread_invoke_renderers, args=())
- renderer_thread.start()
+ if renderer_thread is None or not renderer_thread.is_alive():
+ if renderer_thread is None:
+ logger.info("Starting up the page renderer thread...")
+ else:
+ logger.warning(
+ "The page renderer thread seems to have died; restarting it and hoping for the best."
+ )
+ renderer_thread = Thread(target=thread_invoke_renderers, args=())
+ renderer_thread.start()
- if janitor_thread is None or not janitor_thread.is_alive():
- if janitor_thread is None:
- logger.info("Starting up the memory janitor thread...")
- else:
- logger.warning(
- "The memory janitor thread seems to have died; restarting it and hoping for the best."
- )
- janitor_thread = Thread(target=thread_janitor, args=())
- janitor_thread.start()
+ if janitor_thread is None or not janitor_thread.is_alive():
+ if janitor_thread is None:
+ logger.info("Starting up the memory janitor thread...")
+ else:
+ logger.warning(
+ "The memory janitor thread seems to have died; restarting it and hoping for the best."
+ )
+ janitor_thread = Thread(target=thread_janitor, args=())
+ janitor_thread.start()
- # Have a little break and then check to make sure all threads are still alive.
- logger.debug("Having a little nap...")
- time.sleep(kiosk_constants.check_threads_period_sec)
+ # Have a little break and then check to make sure all threads are still alive.
+ logger.debug("Having a little nap...")
+ time.sleep(kiosk_constants.check_threads_period_sec)
if __name__ == "__main__":