yangtb24 commited on
Commit
d89c20b
·
verified ·
1 Parent(s): 7138622

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -40
app.py CHANGED
@@ -107,48 +107,45 @@ def load_keys():
107
  然后记录到日志中。
108
  使用线程池并发处理每个 key。
109
  """
110
- if keys_str:
111
- keys = [key.strip() for key in keys_str.split(',')]
112
- unique_keys = list(set(keys))
113
- keys_str = ','.join(unique_keys)
114
- os.environ["KEYS"] = keys_str
115
-
116
- logging.info(f"加载的 keys:{unique_keys}")
117
-
118
- with concurrent.futures.ThreadPoolExecutor(
119
- max_workers=1000
120
- ) as executor:
121
- future_to_key = {
122
- executor.submit(
123
- process_key, key, test_model
124
- ): key for key in unique_keys
125
- }
126
 
127
- invalid_keys = []
128
- valid_keys = []
129
-
130
- for future in concurrent.futures.as_completed(
131
- future_to_key
132
- ):
133
- key = future_to_key[future]
134
- try:
135
- key_type = future.result()
136
- if key_type == "invalid":
137
- invalid_keys.append(key)
138
- elif key_type == "valid":
139
- valid_keys.append(key)
140
- except Exception as exc:
141
- logging.error(f"处理 KEY {key} 生成异常: {exc}")
142
-
143
- logging.info(f"无效 KEY:{invalid_keys}")
144
- logging.info(f"有效 KEY:{valid_keys}")
145
-
146
- global invalid_keys_global, valid_keys_global
147
- invalid_keys_global = invalid_keys
148
- valid_keys_global = valid_keys
149
 
150
- else:
151
- logging.warning("环境变量 KEYS 未设置。")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
153
  def process_key(key, test_model):
154
  """
 
107
  然后记录到日志中。
108
  使用线程池并发处理每个 key。
109
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
+ keys = [key.strip() for key in keys_str.split(',')]
112
+ unique_keys = list(set(keys))
113
+ keys_str = ','.join(unique_keys)
114
+ os.environ["KEYS"] = keys_str
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
+ logging.info(f"加载的 keys:{unique_keys}")
117
+
118
+ with concurrent.futures.ThreadPoolExecutor(
119
+ max_workers=1000
120
+ ) as executor:
121
+ future_to_key = {
122
+ executor.submit(
123
+ process_key, key, test_model
124
+ ): key for key in unique_keys
125
+ }
126
+
127
+ invalid_keys = []
128
+ valid_keys = []
129
+
130
+ for future in concurrent.futures.as_completed(
131
+ future_to_key
132
+ ):
133
+ key = future_to_key[future]
134
+ try:
135
+ key_type = future.result()
136
+ if key_type == "invalid":
137
+ invalid_keys.append(key)
138
+ elif key_type == "valid":
139
+ valid_keys.append(key)
140
+ except Exception as exc:
141
+ logging.error(f"处理 KEY {key} 生成异常: {exc}")
142
+
143
+ logging.info(f"无效 KEY:{invalid_keys}")
144
+ logging.info(f"有效 KEY:{valid_keys}")
145
+
146
+ global invalid_keys_global, valid_keys_global
147
+ invalid_keys_global = invalid_keys
148
+ valid_keys_global = valid_keys
149
 
150
  def process_key(key, test_model):
151
  """