Qi28 commited on
Commit
5e7df34
·
verified ·
1 Parent(s): 3d2866b

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +19 -9
server.py CHANGED
@@ -82,29 +82,37 @@ subprocess.run(['rm','/home/aistudio/activate_port.py','/home/aistudio/work/GPT-
82
  subprocess.run(['wget','-O','/home/aistudio/activate_port.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/activate_port.py'])
83
  subprocess.run(['wget','-O','/home/aistudio/work/GPT-SoVITS/api.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/api.py'])
84
  os.chdir('/home/aistudio/work/GPT-SoVITS')
 
 
85
  import subprocess
86
  import psutil
87
  import os
88
 
89
  def is_process_running(process_name):
90
- """Check if a process with the given name is running."""
91
  for proc in psutil.process_iter(attrs=['pid', 'name']):
92
  if process_name in proc.info['name']:
 
93
  return True
94
  return False
95
 
96
  def stop_process(process_name):
97
- """Stop the process with the given name."""
98
  for proc in psutil.process_iter(attrs=['pid', 'name']):
99
  if process_name in proc.info['name']:
100
- print(f"Stopping process: {proc.info['name']} (PID: {proc.info['pid']})")
101
- proc.terminate() # or use proc.kill() to forcefully kill it
102
- proc.wait() # Wait for the process to terminate
 
 
 
 
 
103
 
104
  def run_api_script():
105
  api_script = "/home/aistudio/work/GPT-SoVITS/api.py"
106
 
107
- # Check if api.py is running
108
  if is_process_running("api.py"):
109
  print("api.py 已经在运行...")
110
  stop_process("api.py")
@@ -112,19 +120,21 @@ def run_api_script():
112
  print("api.py 没有在运行...")
113
  subprocess.run(['python', api_script])
114
 
115
- # Execute installation commands
116
  def install_dependencies():
117
  os.system("echo 'y' | sh install.sh")
118
 
119
  subprocess.run(['npm', 'install', '-g', 'localtunnel'])
120
 
121
  subprocess.run(['pip', 'install', '-r','requirements.txt'])
122
-
123
- # Main function to run everything
124
  def main():
125
  run_api_script()
126
  install_dependencies()
127
 
 
 
128
  if __name__ == "__main__":
129
  main()
130
  execute_commands(port_and_commands_json)
 
82
  subprocess.run(['wget','-O','/home/aistudio/activate_port.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/activate_port.py'])
83
  subprocess.run(['wget','-O','/home/aistudio/work/GPT-SoVITS/api.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/api.py'])
84
  os.chdir('/home/aistudio/work/GPT-SoVITS')
85
+
86
+
87
  import subprocess
88
  import psutil
89
  import os
90
 
91
  def is_process_running(process_name):
92
+ """检查指定名称的进程是否在运行。"""
93
  for proc in psutil.process_iter(attrs=['pid', 'name']):
94
  if process_name in proc.info['name']:
95
+ print(f"找到正在运行的进程: {proc.info['name']} (PID: {proc.info['pid']})")
96
  return True
97
  return False
98
 
99
  def stop_process(process_name):
100
+ """停止指定名称的进程。"""
101
  for proc in psutil.process_iter(attrs=['pid', 'name']):
102
  if process_name in proc.info['name']:
103
+ print(f"正在停止进程: {proc.info['name']} (PID: {proc.info['pid']})")
104
+ try:
105
+ proc.terminate() # 尝试正常终止
106
+ proc.wait(timeout=5) # 等待进程终止
107
+ print(f"进程 {proc.info['name']} 成功停止。")
108
+ except psutil.TimeoutExpired:
109
+ print(f"进程未能终止,强制杀死...")
110
+ proc.kill() # 强制杀死该进程
111
 
112
  def run_api_script():
113
  api_script = "/home/aistudio/work/GPT-SoVITS/api.py"
114
 
115
+ # 检查 api.py 是否在运行
116
  if is_process_running("api.py"):
117
  print("api.py 已经在运行...")
118
  stop_process("api.py")
 
120
  print("api.py 没有在运行...")
121
  subprocess.run(['python', api_script])
122
 
123
+ # 执行安装命令
124
  def install_dependencies():
125
  os.system("echo 'y' | sh install.sh")
126
 
127
  subprocess.run(['npm', 'install', '-g', 'localtunnel'])
128
 
129
  subprocess.run(['pip', 'install', '-r','requirements.txt'])
130
+
131
+ # 主函数来执行所有操作
132
  def main():
133
  run_api_script()
134
  install_dependencies()
135
 
136
+
137
+
138
  if __name__ == "__main__":
139
  main()
140
  execute_commands(port_and_commands_json)