mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2025-07-28 06:50:57 +00:00
🐛 fix 多线程占用数据库的问题
This commit is contained in:
@ -122,8 +122,6 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/
|
||||
else:
|
||||
cmd = "nohup"
|
||||
self.process_manager.terminate_all()
|
||||
# 等待所有进程退出
|
||||
self.process_manager.chan_active.receive("main")
|
||||
# 进程退出后重启
|
||||
threading.Thread(target=os.system, args=(f"{cmd} {executable} {' '.join(args)}",)).start()
|
||||
sys.exit(0)
|
||||
@ -143,10 +141,9 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/
|
||||
self.loop.create_task(self.lifespan.before_shutdown()) # 停止前钩子
|
||||
|
||||
if name:
|
||||
self.chan_active.send(1, name)
|
||||
self.process_manager.terminate(name)
|
||||
else:
|
||||
for name in self.process_manager.targets:
|
||||
self.chan_active.send(1, name)
|
||||
self.process_manager.terminate_all()
|
||||
|
||||
def init(self, *args, **kwargs):
|
||||
"""
|
||||
|
@ -0,0 +1,49 @@
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
import nonebot
|
||||
import yaml
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
config = {} # 主进程全局配置,确保加载后读取
|
||||
|
||||
|
||||
class SatoriNodeConfig(BaseModel):
|
||||
host: str = ""
|
||||
port: str = "5500"
|
||||
path: str = ""
|
||||
token: str = ""
|
||||
|
||||
|
||||
class SatoriConfig(BaseModel):
|
||||
comment: str = "These features are still in development. Do not enable in production environment."
|
||||
enable: bool = False
|
||||
hosts: List[SatoriNodeConfig] = [SatoriNodeConfig()]
|
||||
|
||||
|
||||
class BasicConfig(BaseModel):
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 20216
|
||||
superusers: list[str] = []
|
||||
command_start: list[str] = ["/", ""]
|
||||
nickname: list[str] = [f"LiteyukiBot"]
|
||||
satori: SatoriConfig = SatoriConfig()
|
||||
data_path: str = "data/liteyuki"
|
||||
|
||||
|
||||
def load_from_yaml(file: str) -> dict:
|
||||
global config
|
||||
nonebot.logger.debug("Loading config from %s" % file)
|
||||
if not os.path.exists(file):
|
||||
nonebot.logger.warning(f"Config file {file} not found, created default config, please modify it and restart")
|
||||
with open(file, "w", encoding="utf-8") as f:
|
||||
yaml.dump(BasicConfig().dict(), f, default_flow_style=False)
|
||||
|
||||
with open(file, "r", encoding="utf-8") as f:
|
||||
conf = yaml.load(f, Loader=yaml.FullLoader)
|
||||
config = conf
|
||||
if conf is None:
|
||||
nonebot.logger.warning(f"Config file {file} is empty, use default config. please modify it and restart")
|
||||
conf = BasicConfig().dict()
|
||||
return conf
|
||||
|
@ -4,7 +4,6 @@
|
||||
"""
|
||||
import asyncio
|
||||
import inspect
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Coroutine
|
||||
|
||||
|
Reference in New Issue
Block a user