Skip to content

Commit

Permalink
Fixed callsign debug bug, Fixed process spawn and termination bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marios8543 committed Apr 29, 2022
1 parent 7d74e98 commit 89ecca7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion plugin_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, server_instance, plugin_path, loop, live_reload=False) -> Non
self.logger.info(f"plugin_path: {self.plugin_path}")
self.plugins = {}
self.callsigns = {}
self.callsign_matches = {}
self.import_plugins()

if live_reload:
Expand Down Expand Up @@ -85,13 +86,14 @@ def import_plugin(self, file, plugin_directory, refresh=False):
else:
self.plugins[plugin.name].stop()
self.plugins.pop(plugin.name, None)
self.callsigns.pop(plugin.callsign, None)
self.callsigns.pop(self.callsign_matches[file], None)
if plugin.passive:
self.logger.info(f"Plugin {plugin.name} is passive")
callsign = str(time())
plugin.callsign = callsign
self.plugins[plugin.name] = plugin.start()
self.callsigns[callsign] = plugin
self.callsign_matches[file] = callsign
self.logger.info(f"Loaded {plugin.name}")
except Exception as e:
self.logger.error(f"Could not load {file}. {e}")
Expand Down
8 changes: 6 additions & 2 deletions plugin_loader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
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 json import loads, dumps, load
from concurrent.futures import ProcessPoolExecutor
from time import time
from multiprocessing import Process
from signal import signal, SIGINT
from sys import exit

class PluginWrapper:
def __init__(self, file, plugin_directory, plugin_path) -> None:
Expand All @@ -25,6 +27,8 @@ def __init__(self, file, plugin_directory, plugin_path) -> None:
self.passive = not path.isfile(self.file)

def _init(self):
signal(SIGINT, lambda s, f: exit(0))

set_event_loop(new_event_loop())
if self.passive:
return
Expand Down Expand Up @@ -73,7 +77,7 @@ async def _open_socket_if_not_exists(self):
def start(self):
if self.passive:
return self
ProcessPoolExecutor().submit(self._init, self)
Process(target=self._init).start()
return self

def stop(self):
Expand Down

0 comments on commit 89ecca7

Please sign in to comment.