Only reread configuration if file itself modified.
authorBenjamin Braatz <bb@bbraatz.eu>
Mon, 26 Jul 2021 14:23:59 +0000 (16:23 +0200)
committerBenjamin Braatz <bb@bbraatz.eu>
Mon, 26 Jul 2021 14:23:59 +0000 (16:23 +0200)
controlpi/__main__.py

index 848e9b26aa6c6aa4a5a27850ed0fdd3a929f8aaf..8ef2ea2d4ded59e188f6ed64094cc0c4fd9cc80c 100644 (file)
@@ -53,10 +53,11 @@ def read_configuration() -> Dict[str, PluginConf]:
 
 class ConfigChangeHandler(pyinotify.ProcessEvent):
     def process_IN_MODIFY(self, event):
-        print("Configuration file modified.")
-        for task in asyncio.all_tasks():
-            if task is not asyncio.current_task():
-                task.cancel()
+        if event.pathname == os.path.abspath(sys.argv[1]):
+            print(f"Configuration file modified: {event.pathname}")
+            for task in asyncio.all_tasks():
+                if task is not asyncio.current_task():
+                    task.cancel()
 
 
 async def add_config_change_handler() -> pyinotify.AsyncioNotifier:
@@ -65,7 +66,6 @@ async def add_config_change_handler() -> pyinotify.AsyncioNotifier:
     notifier = pyinotify.AsyncioNotifier(wm, loop,
                                          default_proc_fun=ConfigChangeHandler())
     wm.add_watch(os.path.dirname(sys.argv[1]), pyinotify.ALL_EVENTS)
-    wm.add_watch(sys.argv[1], pyinotify.ALL_EVENTS)
     return notifier