Skip to content

Commit

Permalink
made watchdog run in its own thread - see #612
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbarratt committed Jul 8, 2024
1 parent bfe01ff commit 27ca121
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/pyscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 27ca121

Please sign in to comment.