Update SW_run.py
Browse files
SW_run.py
CHANGED
@@ -2,12 +2,18 @@ import subprocess
|
|
2 |
import sys
|
3 |
import logging
|
4 |
import os
|
|
|
5 |
|
6 |
# 检查是否存在 logs_run.txt 文件,如果存在则删除它
|
7 |
log_file = '/bushu/logs_run.txt'
|
8 |
if os.path.exists(log_file):
|
9 |
os.remove(log_file)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
# 配置日志
|
12 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
@@ -22,13 +28,25 @@ logging.getLogger().addHandler(console_handler)
|
|
22 |
sys.stdout = logging.getLogger().handlers[0].stream
|
23 |
sys.stderr = logging.getLogger().handlers[0].stream
|
24 |
|
25 |
-
#
|
26 |
os.chdir('/bushu/ui')
|
27 |
|
28 |
try:
|
29 |
-
# 在try
|
30 |
-
with open(log_file, 'a') as log_file_handle:
|
31 |
-
subprocess.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
except subprocess.CalledProcessError as e:
|
34 |
# 捕获异常并记录到日志文件
|
|
|
2 |
import sys
|
3 |
import logging
|
4 |
import os
|
5 |
+
import binascii # 用于将文本转换为十六进制
|
6 |
|
7 |
# 检查是否存在 logs_run.txt 文件,如果存在则删除它
|
8 |
log_file = '/bushu/logs_run.txt'
|
9 |
if os.path.exists(log_file):
|
10 |
os.remove(log_file)
|
11 |
|
12 |
+
# 检查是否存在 url.txt 文件,如果存在则删除它
|
13 |
+
url_file = '/bushu/url.txt'
|
14 |
+
if os.path.exists(url_file):
|
15 |
+
os.remove(url_file)
|
16 |
+
|
17 |
# 配置日志
|
18 |
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
19 |
|
|
|
28 |
sys.stdout = logging.getLogger().handlers[0].stream
|
29 |
sys.stderr = logging.getLogger().handlers[0].stream
|
30 |
|
31 |
+
# 更改当前工作目录为 /bushu/ui
|
32 |
os.chdir('/bushu/ui')
|
33 |
|
34 |
try:
|
35 |
+
# 在 try 块中运行 /bushu/ui/launch.py,并将输出重定向到日志文件
|
36 |
+
with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle:
|
37 |
+
process = subprocess.Popen(['python', '/bushu/ui/launch.py', '--skip-torch-cuda-test', '--share', '--listen', '--xformers', '--enable-insecure-extension-access', '--gradio-queue', '--multiple'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
38 |
+
|
39 |
+
for line in process.stdout:
|
40 |
+
if "Running" in line:
|
41 |
+
# 将包含 "Running" 的行以十六进制形式写入 url.txt
|
42 |
+
hex_line = binascii.hexlify(line.encode()).decode()
|
43 |
+
url_file_handle.write(hex_line + '\n\n')
|
44 |
+
else:
|
45 |
+
# 将其他行写入日志文件
|
46 |
+
log_file_handle.write(line)
|
47 |
+
log_file_handle.flush()
|
48 |
+
|
49 |
+
process.wait()
|
50 |
|
51 |
except subprocess.CalledProcessError as e:
|
52 |
# 捕获异常并记录到日志文件
|