mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 11:29:39 +08:00
perf: 完善重载后的启动流程
This commit is contained in:
10
main.py
10
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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("重载完成")
|
||||
|
||||
Reference in New Issue
Block a user