X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=kiosk.py;fp=kiosk.py;h=75abed797a54748c79e33f774e871a1f79ac1923;hb=1d6c45c8350ba6e5cb7a9fdc30d0663667ded6d4;hp=24821600a7a0676b9d6e383885db36fabfe5c861;hpb=5cd909241fefc418e495e633243403592339991a;p=kiosk.git diff --git a/kiosk.py b/kiosk.py index 2482160..75abed7 100755 --- a/kiosk.py +++ b/kiosk.py @@ -41,8 +41,8 @@ cfg = config.add_commandline_args( 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 @@ -217,8 +217,8 @@ def process_command( 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 @@ -657,8 +657,8 @@ def renderer_update_internal_stats_page( f.write("") +@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] = {} @@ -715,58 +715,60 @@ def main() -> None: 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__":