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__":
while True:
key = self.should_render(keys_to_skip)
if key is None:
- logger.info(
- f'renderer: Found nothing to do in "{self.get_name()}"; returning.'
- )
+ logger.info(f'Found nothing to do in "{self.get_name()}"; returning.')
break
if key in tries_per_key:
tries_per_key[key] += 1
else:
tries_per_key[key] = 0
- op = f'{self.get_name()}.{key}'
+ op = f"{self.get_name()}.{key}"
if tries_per_key[key] >= 3:
- logger.warning(
- f'renderer: Too many failures in "{op}"; giving up.'
- )
+ logger.warning(f'Too many failures in "{op}"; giving up.')
keys_to_skip.add(key)
else:
- msg = f'renderer: executing "{op}"'
+ msg = f'Executing "{op}"'
if tries_per_key[key] > 1:
- msg = msg + f' (retry #{tries_per_key[key]})'
+ msg = msg + f" (retry #{tries_per_key[key]})"
logger.info(msg)
if self.periodic_render(key):
- logger.debug(f'renderer: {op} succeeded.')
+ logger.debug(f'"{op}" succeeded.')
self.last_runs[key] = time.time()
else:
- logger.warning(f'renderer: {op} failed; returned False.')
+ logger.warning(f'"{op}" failed; returned False.')
@invocation_logged
@abstractmethod