diff options
| author | Jonas Dellinger <jonas.dellinger@2trde.com> | 2022-06-16 19:09:06 +0200 |
|---|---|---|
| committer | Jonas Dellinger <jonas.dellinger@2trde.com> | 2022-06-16 19:09:06 +0200 |
| commit | 70821ee47b74eb50f70bd085b4fc88b316b1c042 (patch) | |
| tree | 15db00091f5421d69430b4dc82e5d9cbc6f472c5 | |
| parent | 0a12fe6102da33977548ba0c277bd4fe34e262ab (diff) | |
| download | decky-loader-plugin-backend-language-independent.tar.gz decky-loader-plugin-backend-language-independent.zip | |
Add stop functionalityplugin-backend-language-independent
| -rw-r--r-- | backend/plugin/binary_plugin.py | 19 | ||||
| -rw-r--r-- | backend/plugin/passive_plugin.py | 5 | ||||
| -rw-r--r-- | backend/plugin/python_plugin.py | 18 | ||||
| -rw-r--r-- | backend/plugin_wrapper.py | 3 |
4 files changed, 37 insertions, 8 deletions
diff --git a/backend/plugin/binary_plugin.py b/backend/plugin/binary_plugin.py index 4bd4f39b..30cb8ae1 100644 --- a/backend/plugin/binary_plugin.py +++ b/backend/plugin/binary_plugin.py @@ -10,6 +10,8 @@ class BinaryPlugin: def __init__(self, plugin_directory, file_name, flags, logger) -> None: self.server = PluginProtocolServer(self) self.connection = None + self.process = None + self.flags = flags self.logger = logger @@ -18,7 +20,7 @@ class BinaryPlugin: async def start(self): - if self.connection: + if self.connection and self.connection.is_serving: self.connection.close() self.unix_socket_path = BinaryPlugin.generate_socket_path() @@ -29,11 +31,20 @@ class BinaryPlugin: self.process = await subprocess.create_subprocess_exec(join(self.plugin_directory, self.file_name), env=env) get_event_loop().create_task(self.process_loop()) + async def stop(self): + self.stopped = True + if self.connection and self.connection.is_serving: + self.connection.close() + + if self.process and self.process.is_alive: + self.process.terminate() + async def process_loop(self): await self.process.wait() - self.logger.info("backend process was killed - restarting in 10 seconds") - await sleep(10) - await self.start() + if not self.stopped: + self.logger.info("backend process was killed - restarting in 10 seconds") + await sleep(10) + await self.start() def generate_socket_path(): tmp_dir = mkdtemp("decky-plugin") diff --git a/backend/plugin/passive_plugin.py b/backend/plugin/passive_plugin.py index 9b7907bb..a8c5add3 100644 --- a/backend/plugin/passive_plugin.py +++ b/backend/plugin/passive_plugin.py @@ -12,4 +12,7 @@ class PassivePlugin: pass async def start(self): - pass# Empty stub + pass + + async def stop(self): + pass diff --git a/backend/plugin/python_plugin.py b/backend/plugin/python_plugin.py index c2833088..f7270e2d 100644 --- a/backend/plugin/python_plugin.py +++ b/backend/plugin/python_plugin.py @@ -53,6 +53,8 @@ class PythonPlugin: self.client = PluginProtocolClient(self, logger) self.server = PluginProtocolServer(self) self.connection = None + self.process = None + self.stopped = False self.plugin_directory = plugin_directory self.file_name = file_name @@ -93,12 +95,22 @@ class PythonPlugin: self.process = multiprocessing.Process(target=self._init) self.process.start() get_event_loop().create_task(self.process_loop()) + self.stopped = False + + async def stop(self): + self.stopped = True + if self.connection: + self.connection.close() + + if self.process and self.process.is_alive: + self.process.terminate() async def process_loop(self): await get_event_loop().run_in_executor(None, self.process.join) - self.logger.info("backend process was killed - restarting in 10 seconds") - await sleep(10) - await self.start() + if not self.stopped: + self.logger.info("backend process was killed - restarting in 10 seconds") + await sleep(10) + await self.start() # called on the server/loader process async def call_method(self, method_name, method_args): diff --git a/backend/plugin_wrapper.py b/backend/plugin_wrapper.py index d41454df..b158f861 100644 --- a/backend/plugin_wrapper.py +++ b/backend/plugin_wrapper.py @@ -30,5 +30,8 @@ class PluginWrapper: def start(self): return self.backend.start() + def stop(self): + return self.backend.stop() + def __str__(self) -> str: return self.name |
