From 27ca121630a6163eed53578ac48d25935b188a89 Mon Sep 17 00:00:00 2001 From: Craig Barratt <19445341+craigbarratt@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:36:33 +1000 Subject: [PATCH] made watchdog run in its own thread - see #612 --- custom_components/pyscript/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/pyscript/__init__.py b/custom_components/pyscript/__init__.py index b755744..20f4549 100644 --- a/custom_components/pyscript/__init__.py +++ b/custom_components/pyscript/__init__.py @@ -150,8 +150,12 @@ async def watchdog_start( class WatchDogHandler(FileSystemEventHandler): """Class for handling watchdog events.""" - def __init__(self, watchdog_q: asyncio.Queue) -> None: + def __init__( + self, watchdog_q: asyncio.Queue, observer: watchdog.observers.Observer, path: str + ) -> None: self.watchdog_q = watchdog_q + self._observer = observer + self._observer.schedule(self, path, recursive=True) def process(self, event: FileSystemEvent) -> None: """Send watchdog events to main loop task.""" @@ -221,7 +225,7 @@ def check_event(event, do_reload: bool) -> bool: hass.data[DOMAIN][WATCHDOG_OBSERVER] = observer hass.data[DOMAIN][WATCHDOG_TASK] = Function.create_task(task_watchdog(watchdog_q)) - observer.schedule(WatchDogHandler(watchdog_q), pyscript_folder, recursive=True) + await hass.async_add_executor_job(WatchDogHandler, watchdog_q, observer, pyscript_folder) async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: