diff --git a/main.py b/main.py index b7fc6d91..0a124a57 100644 --- a/main.py +++ b/main.py @@ -87,6 +87,7 @@ def main(first_time_init=False): try: time.sleep(10000) if qqbot != pkg.utils.context.get_qqbot_manager(): # 已经reload了 + logging.info("以前的main流程由于reload退出") break except KeyboardInterrupt: stop() @@ -103,15 +104,6 @@ def stop(): qqbot_inst = pkg.utils.context.get_qqbot_manager() assert isinstance(qqbot_inst, pkg.qqbot.manager.QQBotManager) - # try: - # asyncio.run(qqbot_inst.bot.shutdown()) - # except ValueError: - # pass - # - # import mirai.utils - # MiraiRunner.__class__._instance = None - # mirai.utils.Singleton._instance = None - pkg.utils.context.get_openai_manager().key_mgr.dump_fee() for session in pkg.openai.session.sessions: logging.info('持久化session: %s', session) diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 0145fcec..180bd1ac 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -161,21 +161,16 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes and not config.include_image_description): reply.append(" ".join(params)) elif cmd == 'reload' and launcher_type == 'person' and launcher_id == config.admin_qq: - try: - # pkg.utils.reloader.reload_all() - threading.Thread(target=pkg.utils.reloader.reload_all, daemon=True).start() - # reply = ["[bot]已重新加载所有模块"] - except Exception as e: - logging.error("reload failed:{}".format(e)) - reply = ["[bot]重载失败:{}".format(e)] + def reload_task(): + pkg.utils.reloader.reload_all() + + threading.Thread(target=reload_task, daemon=True).start() elif cmd == 'update' and launcher_type == 'person' and launcher_id == config.admin_qq: - try: + def update_task(): pkg.utils.updater.update_all() pkg.utils.reloader.reload_all() - reply = ["[bot]已更新所有模块"] - except Exception as e: - logging.error("update failed:{}".format(e)) - reply = ["[bot]更新失败:{}".format(e)] + + threading.Thread(target=update_task, daemon=True).start() except Exception as e: mgr.notify_admin("{}指令执行失败:{}".format(session_name, e)) logging.exception(e) diff --git a/pkg/utils/reloader.py b/pkg/utils/reloader.py index 1a883546..10bfff49 100644 --- a/pkg/utils/reloader.py +++ b/pkg/utils/reloader.py @@ -37,6 +37,7 @@ def reload_all(): # 执行启动流程 logging.info("执行程序启动流程") - main.main() + threading.Thread(target=main.main, args=(False,), daemon=False).start() logging.info('程序启动完成') + pkg.utils.context.get_qqbot_manager().notify_admin("重载完成")