Fixed callsign debug bug, Fixed process spawn and termination bug

This commit is contained in:
marios
2022-04-29 21:51:01 +03:00
parent 7d74e98f4f
commit 89ecca7c30
2 changed files with 9 additions and 3 deletions
+3 -1
View File
@@ -58,6 +58,7 @@ class Loader:
self.logger.info(f"plugin_path: {self.plugin_path}") self.logger.info(f"plugin_path: {self.plugin_path}")
self.plugins = {} self.plugins = {}
self.callsigns = {} self.callsigns = {}
self.callsign_matches = {}
self.import_plugins() self.import_plugins()
if live_reload: if live_reload:
@@ -85,13 +86,14 @@ class Loader:
else: else:
self.plugins[plugin.name].stop() self.plugins[plugin.name].stop()
self.plugins.pop(plugin.name, None) self.plugins.pop(plugin.name, None)
self.callsigns.pop(plugin.callsign, None) self.callsigns.pop(self.callsign_matches[file], None)
if plugin.passive: if plugin.passive:
self.logger.info(f"Plugin {plugin.name} is passive") self.logger.info(f"Plugin {plugin.name} is passive")
callsign = str(time()) callsign = str(time())
plugin.callsign = callsign plugin.callsign = callsign
self.plugins[plugin.name] = plugin.start() self.plugins[plugin.name] = plugin.start()
self.callsigns[callsign] = plugin self.callsigns[callsign] = plugin
self.callsign_matches[file] = callsign
self.logger.info(f"Loaded {plugin.name}") self.logger.info(f"Loaded {plugin.name}")
except Exception as e: except Exception as e:
self.logger.error(f"Could not load {file}. {e}") self.logger.error(f"Could not load {file}. {e}")
+6 -2
View File
@@ -2,8 +2,10 @@ from importlib.util import spec_from_file_location, module_from_spec
from asyncio import get_event_loop, new_event_loop, set_event_loop, start_unix_server, open_unix_connection, sleep, Lock from asyncio import get_event_loop, new_event_loop, set_event_loop, start_unix_server, open_unix_connection, sleep, Lock
from os import path, setuid from os import path, setuid
from json import loads, dumps, load from json import loads, dumps, load
from concurrent.futures import ProcessPoolExecutor
from time import time from time import time
from multiprocessing import Process
from signal import signal, SIGINT
from sys import exit
class PluginWrapper: class PluginWrapper:
def __init__(self, file, plugin_directory, plugin_path) -> None: def __init__(self, file, plugin_directory, plugin_path) -> None:
@@ -25,6 +27,8 @@ class PluginWrapper:
self.passive = not path.isfile(self.file) self.passive = not path.isfile(self.file)
def _init(self): def _init(self):
signal(SIGINT, lambda s, f: exit(0))
set_event_loop(new_event_loop()) set_event_loop(new_event_loop())
if self.passive: if self.passive:
return return
@@ -73,7 +77,7 @@ class PluginWrapper:
def start(self): def start(self):
if self.passive: if self.passive:
return self return self
ProcessPoolExecutor().submit(self._init, self) Process(target=self._init).start()
return self return self
def stop(self): def stop(self):