Qilan2 commited on
Commit
2fa4633
·
verified ·
1 Parent(s): 62207eb

Update server10.py

Browse files
Files changed (1) hide show
  1. server10.py +34 -14
server10.py CHANGED
@@ -285,21 +285,39 @@ def frp(configs, backstage):
285
 
286
  def monitor_port():
287
  while True:
288
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
289
- result = sock.connect_ex(('localhost', 8000))
290
- if result == 0:
291
- print(f"端口 8000 正在使用中")
 
 
 
 
 
 
 
 
 
 
292
  else:
293
- print(f"端口 8000 未被使用")
294
- # 读取 config.ini 中的 monitor_port_enabled 配置项
295
- config = configparser.ConfigParser()
296
- config.read('/data/config.ini')
297
- monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False)
298
- if monitor_port_enabled:
299
- backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
300
- backup_thread.start()
301
- else:
302
- print(f"monitor_port_enabled 为False跳过")
 
 
 
 
 
 
 
 
303
 
304
  time.sleep(5) # 每5秒检查一次
305
  def Run_SillyTavern():
@@ -435,6 +453,8 @@ if os.path.exists(f'/data/{huggingface_Data_name}.zip'):
435
  if now.hour == 6 and now.minute < 5: # 6:00-6:05之间退出
436
  print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
437
  break
 
 
438
 
439
  if backup_thread.is_alive():
440
  print("备份线程仍在运行...")
 
285
 
286
  def monitor_port():
287
  while True:
288
+ url = "http://127.0.0.1:8000/v1"
289
+ response = requests.get(url, timeout=30)
290
+ if response.status_code == 403:
291
+ print("SillyTavern运行中")
292
+ # break
293
+ else:
294
+ print("SillyTavern未运行,状态码:", response.status_code, n)
295
+ # 读取 config.ini 中的 monitor_port_enabled 配置项
296
+ config = configparser.ConfigParser()
297
+ config.read('/data/config.ini')
298
+ monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False)
299
+ if monitor_port_enabled:
300
+ backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
301
+ backup_thread.start()
302
  else:
303
+ print(f"monitor_port_enabled 为False跳过")
304
+
305
+
306
+ # with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
307
+ # result = sock.connect_ex(('localhost', 8000))
308
+ # if result == 0:
309
+ # print(f"端口 8000 正在使用中")
310
+ # else:
311
+ # print(f"端口 8000 未被使用")
312
+ # # 读取 config.ini 中的 monitor_port_enabled 配置项
313
+ # config = configparser.ConfigParser()
314
+ # config.read('/data/config.ini')
315
+ # monitor_port_enabled = config.getboolean('general', 'monitor_port_enabled', fallback=False)
316
+ # if monitor_port_enabled:
317
+ # backup_thread = threading.Thread(target=Run_SillyTavern, daemon=True)
318
+ # backup_thread.start()
319
+ # else:
320
+ # print(f"monitor_port_enabled 为False跳过")
321
 
322
  time.sleep(5) # 每5秒检查一次
323
  def Run_SillyTavern():
 
453
  if now.hour == 6 and now.minute < 5: # 6:00-6:05之间退出
454
  print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环")
455
  break
456
+ else:
457
+ print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点")
458
 
459
  if backup_thread.is_alive():
460
  print("备份线程仍在运行...")