mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
chore: 代码格式优化
This commit is contained in:
17
main.py
17
main.py
@@ -293,13 +293,16 @@ def stop():
|
||||
if not isinstance(e, KeyboardInterrupt):
|
||||
raise e
|
||||
|
||||
|
||||
# 临时函数,用于加载config和上下文,未来统一放在config类
|
||||
def load_config():
|
||||
|
||||
# 存在性校验
|
||||
if not os.path.exists('config.py'):
|
||||
shutil.copy('config-template.py', 'config.py')
|
||||
print('请先在config.py中填写配置')
|
||||
sys.exit(0)
|
||||
|
||||
# 完整性校验
|
||||
is_integrity = True
|
||||
config_template = importlib.import_module('config-template')
|
||||
@@ -313,9 +316,11 @@ def load_config():
|
||||
logging.warning("配置文件不完整,请依据config-template.py检查config.py")
|
||||
logging.warning("以上配置已被设为默认值,将在5秒后继续启动... ")
|
||||
time.sleep(5)
|
||||
#context配置
|
||||
|
||||
# 存进上下文
|
||||
pkg.utils.context.set_config(config)
|
||||
|
||||
|
||||
def check_file():
|
||||
# 检查是否有banlist.py,如果没有就把banlist-template.py复制一份
|
||||
if not os.path.exists('banlist.py'):
|
||||
@@ -335,6 +340,7 @@ def check_file():
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
||||
|
||||
def main():
|
||||
# 加载配置
|
||||
load_config()
|
||||
@@ -350,9 +356,10 @@ def main():
|
||||
admin_pool_num=config.admin_pool_num,
|
||||
user_pool_num=config.user_pool_num
|
||||
)
|
||||
# 存进上下文
|
||||
pkg.utils.context.set_thread_ctl(thread_ctl)
|
||||
|
||||
# 控制台指令处理
|
||||
# 启动指令处理
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'init_db':
|
||||
init_db()
|
||||
sys.exit(0)
|
||||
@@ -363,10 +370,7 @@ def main():
|
||||
updater.update_all(cli=True)
|
||||
sys.exit(0)
|
||||
|
||||
# 不知道干啥的
|
||||
# import pkg.utils.configmgr
|
||||
#
|
||||
# pkg.utils.configmgr.set_config_and_reload("quote_origin", False)
|
||||
# 关闭urllib的http警告
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
|
||||
pkg.utils.context.get_thread_ctl().submit_sys_task(
|
||||
@@ -388,6 +392,7 @@ def main():
|
||||
cmd = "kill -9 {}".format(os.getpid())
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import threading
|
||||
from pkg.utils import ThreadCtl
|
||||
|
||||
|
||||
context = {
|
||||
'inst': {
|
||||
@@ -78,14 +80,15 @@ def get_plugin_host():
|
||||
context_lock.release()
|
||||
return t
|
||||
|
||||
|
||||
def set_thread_ctl(inst):
|
||||
context_lock.acquire()
|
||||
context['pool_ctl'] = inst
|
||||
context_lock.release()
|
||||
|
||||
from pkg.utils import ThreadCtl
|
||||
|
||||
def get_thread_ctl() -> ThreadCtl:
|
||||
context_lock.acquire()
|
||||
t = context['pool_ctl']
|
||||
t: ThreadCtl = context['pool_ctl']
|
||||
context_lock.release()
|
||||
return t
|
||||
@@ -1,7 +1,9 @@
|
||||
from concurrent.futures import ThreadPoolExecutor, Future
|
||||
import threading, time
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
class Pool():
|
||||
|
||||
class Pool:
|
||||
'''
|
||||
线程池结构
|
||||
'''
|
||||
@@ -28,7 +30,8 @@ class Pool():
|
||||
continue
|
||||
time.sleep(1)
|
||||
|
||||
class ThreadCtl():
|
||||
|
||||
class ThreadCtl:
|
||||
def __init__(self, sys_pool_num, admin_pool_num, user_pool_num):
|
||||
'''
|
||||
线程池控制类
|
||||
|
||||
Reference in New Issue
Block a user