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