From f23b7d5376b5d3dc64ebf817b62c23c0410ab6be Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 30 Jan 2022 04:16:59 -0500 Subject: [PATCH] plugin handler spawns daemon threads instead of calling the hooks all blocking-like and such --- README.md | 5 +++-- plugin_manager.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e26c0a1..35fdf29 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ framework for discord bots that uses contained files for individual feature plug * make sure broken sockets are properly addressed with a resume or reconnect * initial presence in config * full REST api implementation -* plugins need to be asynchronously run (or something) + ### plugins: * save session config to file @@ -25,4 +25,5 @@ framework for discord bots that uses contained files for individual feature plug * ~~plugin manager & hook integration~~ * ~~default plugins so the bot does _something_ out of the box~~ * ~~plugin reloading, user (command) authentication, etc. will also probably be written in plugin form~~ -* ~~take config as cli param~~ \ No newline at end of file +* ~~take config as cli param~~ +* ~~plugins need to be asynchronously run (or something)~~ \ No newline at end of file diff --git a/plugin_manager.py b/plugin_manager.py index 8f1b945..f03b632 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -1,6 +1,6 @@ import os import sys - +import threading class plugin_manager(): def __init__(self, logger, plugin_path = "./plugins"): self.logger = logger @@ -26,7 +26,7 @@ class plugin_manager(): for plugin in self.plugins_loaded: if event in plugin.hooks: try: - getattr(plugin, "run")(event, ctx, bot) + threading.Thread(target=getattr(plugin, "run"), args=(event, ctx, bot), daemon=True).start() except Exception as e: bot.logger.write(e) def __del__(self):