From c3cc449fee89bf9ba7b4cdeca37a4fae2011a504 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 10 Feb 2023 17:22:26 -0500 Subject: [PATCH] Add _unload functionality --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.py b/main.py index 3e7acb9..bcf1c93 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,18 @@ class Plugin: # Asyncio-compatible long-running code, executed in a task when the plugin is loaded async def _main(self): # startup + print("PowerTools starting...") self.backend_proc = subprocess.Popen([PARENT_DIR + "/bin/backend"]) while True: await asyncio.sleep(1) + + async def _unload(self): + # shutdown + print("PowerTools unloading...") + if self.backend_proc is not None: + self.backend_proc.terminate() + try: + self.backend_proc.wait(timeout=5) # 5 seconds timeout + except subprocess.TimeoutExpired: + self.backend_proc.kill() + self.backend_proc = None