diff --git a/base/rules.db b/base/rules.db index 1414a80857c52a0d7edb12293f75513257f71f92..c596c67bba5a8a12a5607b59ad025f2b80f99603 100644 Binary files a/base/rules.db and b/base/rules.db differ diff --git a/controllers/vod.py b/controllers/vod.py index bee6d1691c5ff94b8854226911b2cfc56d5d92c7..b5907274964161fc0dd9028503ef2dc43fcd72a5 100644 --- a/controllers/vod.py +++ b/controllers/vod.py @@ -5,7 +5,7 @@ # Date : 2022/9/6 import json -from flask import Blueprint,abort,request,render_template,render_template_string,jsonify,make_response,redirect +from flask import Blueprint,abort,request,render_template,render_template_string,jsonify,make_response,redirect,current_app from time import time from utils.web import getParmas,get_interval from utils.cfg import cfg @@ -46,7 +46,7 @@ def search_one_py(rule, wd, before: str = ''): print(f'{rule}发生错误:{e}') return None -def search_one(rule, wd, before: str = ''): +def search_one(rule, wd, before: str = '',env:dict=None,app=None): t1 = time() if not before: with open('js/模板.js', encoding='utf-8') as f: @@ -57,9 +57,12 @@ def search_one(rule, wd, before: str = ''): try: with open(js_path, encoding='utf-8') as f2: jscode = f2.read() - env = get_env() if env: - jscode = render_template_string(jscode, **env) + # 渲染字符串文本 render_template_string 必须带 flask的上下文 + with app.app_context(): + jscode = render_template_string(jscode, **env) + # if '007' in rule: + # print(rule,jscode) jscode = before + jscode + end_code # print(jscode) ctx.eval(jscode) @@ -139,8 +142,14 @@ def merged_hide(merged_rules): logger.info(f'数据库筛选隐藏规则耗时{get_interval(t1)}毫秒,共计{all_cnt}条规则,隐藏后可渲染{len(merged_rules)}条规则') return merged_rules +def disable_exit_for_threadpool_executor(): + import atexit + import concurrent.futures + atexit.unregister(concurrent.futures.thread._python_exit) + def multi_search(wd): lsg = storage_service() + env = get_env() t1 = time() try: timeout = round(int(lsg.getItem('SEARCH_TIMEOUT',5000))/1000,2) @@ -167,7 +176,7 @@ def multi_search(wd): with ThreadPoolExecutor(max_workers=len(search_sites)) as executor: to_do = [] for site in search_sites: - future = executor.submit(search_one, site, wd, before) + future = executor.submit(search_one, site, wd, before,env,current_app._get_current_object()) to_do.append(future) try: for future in as_completed(to_do, timeout=timeout): # 并发执行 @@ -180,6 +189,8 @@ def multi_search(wd): import atexit atexit.unregister(thread._python_exit) executor.shutdown = lambda wait: None + + # disable_exit_for_threadpool_executor() logger.info(f'drpy聚搜{len(search_sites)}个源共计耗时{get_interval(t1)}毫秒') return jsonify({ "list": res @@ -323,7 +334,7 @@ def vod_home(): return jsonify(data) if wd: # 搜索 if rule == 'drpy': - # print(f'准备单独处理聚合搜索:{wd}') + print(f'准备单独处理聚合搜索:{wd}') return multi_search(wd) # return multi_search2(wd) else: diff --git a/js/version.txt b/js/version.txt index d83e8e64060a3a6b2bcdb0a11853bdb1fe5eaea2..4e4a0e4c1f4c6a16fc9c73c0de42caca7c2f20a3 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.9.22beta1 \ No newline at end of file +3.9.22beta2 \ No newline at end of file