Update server.py
Browse files
server.py
CHANGED
|
@@ -147,25 +147,38 @@ def download_and_extract_gpt_sovits():
|
|
| 147 |
print('GPT-SoVITS 文件夹已存在,无需下载和解压.')
|
| 148 |
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
def execute_commands(port_and_commands_json):
|
| 151 |
try:
|
| 152 |
# 解析 JSON 字符串
|
| 153 |
port_and_commands_list = json.loads(port_and_commands_json)
|
| 154 |
|
| 155 |
-
|
| 156 |
|
| 157 |
for item in port_and_commands_list:
|
| 158 |
port = item['port']
|
| 159 |
command = item['command']
|
| 160 |
|
| 161 |
-
#
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
#
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
|
| 170 |
except json.JSONDecodeError as e:
|
| 171 |
print(f"Failed to decode JSON: {e}")
|
|
|
|
| 147 |
print('GPT-SoVITS 文件夹已存在,无需下载和解压.')
|
| 148 |
|
| 149 |
|
| 150 |
+
def execute_command(port, command):
|
| 151 |
+
# 构造完整的命令字符串
|
| 152 |
+
full_command = f'python /home/aistudio/work/GPT-SoVITS/api.py -p {port} {command}'
|
| 153 |
+
|
| 154 |
+
# 执行命令并将其放入后台
|
| 155 |
+
print(f'Executing command on port {port}: {full_command}')
|
| 156 |
+
process = subprocess.Popen(full_command, shell=True) # 使用 Popen 启动进程
|
| 157 |
+
|
| 158 |
+
# 等待进程完成(可选)
|
| 159 |
+
# process.wait()
|
| 160 |
+
|
| 161 |
def execute_commands(port_and_commands_json):
|
| 162 |
try:
|
| 163 |
# 解析 JSON 字符串
|
| 164 |
port_and_commands_list = json.loads(port_and_commands_json)
|
| 165 |
|
| 166 |
+
threads = [] # 用于存储线程对象
|
| 167 |
|
| 168 |
for item in port_and_commands_list:
|
| 169 |
port = item['port']
|
| 170 |
command = item['command']
|
| 171 |
|
| 172 |
+
# 创建并启动线程来执行命令
|
| 173 |
+
thread = threading.Thread(target=execute_command, args=(port, command))
|
| 174 |
+
thread.start()
|
| 175 |
+
threads.append(thread) # 将线程对象添加到列表
|
| 176 |
|
| 177 |
+
time.sleep(30) # 可选:控制启动新线程的频率
|
| 178 |
+
|
| 179 |
+
# # 等待所有线程完成(可选)
|
| 180 |
+
# for thread in threads:
|
| 181 |
+
# thread.join()
|
| 182 |
|
| 183 |
except json.JSONDecodeError as e:
|
| 184 |
print(f"Failed to decode JSON: {e}")
|