Update SW_run.py
Browse files
SW_run.py
CHANGED
|
@@ -1,51 +1,59 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import logging
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 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 |
-
|
| 14 |
-
# 创建一个将输出同时发送到控制台和日志文件的处理程序
|
| 15 |
-
console_handler = logging.StreamHandler(sys.stdout)
|
| 16 |
-
console_handler.setLevel(logging.INFO)
|
| 17 |
-
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
| 18 |
-
console_handler.setFormatter(formatter)
|
| 19 |
-
logging.getLogger().addHandler(console_handler)
|
| 20 |
-
|
| 21 |
-
# 重定向标准输出和标准错误到日志文件和控制台
|
| 22 |
-
sys.stdout = logging.getLogger().handlers[0].stream
|
| 23 |
-
sys.stderr = logging.getLogger().handlers[0].stream
|
| 24 |
-
|
| 25 |
-
# 切换到 /bushu/ui 目录
|
| 26 |
-
os.chdir('/bushu/ui')
|
| 27 |
-
|
| 28 |
-
try:
|
| 29 |
-
# 在try块中运行 /bushu/ui/launch.py,并将输出重定向到日志文件
|
| 30 |
-
with open(log_file, 'a') as log_file_handle:
|
| 31 |
-
cmd = ['python', '/bushu/ui/launch.py', '--share', '-o', '/bushu/out_url.txt']
|
| 32 |
-
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
|
| 33 |
-
|
| 34 |
-
# 保存包含"Running"的行到url.txt
|
| 35 |
-
with open('/bushu/url.txt', 'a') as url_file:
|
| 36 |
-
while process.poll() is None:
|
| 37 |
-
line = process.stdout.readline()
|
| 38 |
-
if "Running" in line:
|
| 39 |
-
url_file.write(line)
|
| 40 |
-
print(line, end='') # 输出包含"Running"的行到控制台
|
| 41 |
-
log_file_handle.write(line)
|
| 42 |
-
except subprocess.CalledProcessError as e:
|
| 43 |
-
# 捕获异常并记录到日志文件
|
| 44 |
-
logging.exception(f"程序发生异常: {e}")
|
| 45 |
-
except Exception as e:
|
| 46 |
-
# 捕获其他异常并记录到日志文件
|
| 47 |
-
logging.exception(f"程序发生异常: {e}")
|
| 48 |
-
finally:
|
| 49 |
-
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
| 50 |
-
logging.getLogger().removeHandler(console_handler)
|
| 51 |
-
console_handler.close()
|
|
|
|
| 1 |
+
# 导入所需的模块
|
| 2 |
+
from modules import launch_utils
|
|
|
|
| 3 |
import os
|
| 4 |
+
import subprocess
|
| 5 |
+
import threading
|
| 6 |
+
|
| 7 |
+
# 设置启动参数
|
| 8 |
+
args = launch_utils.args
|
| 9 |
+
args.listen = True
|
| 10 |
+
args.xformers = True
|
| 11 |
+
args.enable_insecure_extension_access = True
|
| 12 |
+
args.theme = "dark"
|
| 13 |
+
args.gradio_queue = True
|
| 14 |
+
args.multiple = True
|
| 15 |
+
args.no_download_sd_model = True
|
| 16 |
+
args.share = True
|
| 17 |
+
|
| 18 |
+
python = launch_utils.python
|
| 19 |
+
git = launch_utils.git
|
| 20 |
+
index_url = launch_utils.index_url
|
| 21 |
+
dir_repos = launch_utils.dir_repos
|
| 22 |
+
|
| 23 |
+
commit_hash = launch_utils.commit_hash
|
| 24 |
+
git_tag = launch_utils.git_tag
|
| 25 |
+
|
| 26 |
+
run = launch_utils.run
|
| 27 |
+
is_installed = launch_utils.is_installed
|
| 28 |
+
repo_dir = launch_utils.repo_dir
|
| 29 |
+
|
| 30 |
+
run_pip = launch_utils.run_pip
|
| 31 |
+
check_run_python = launch_utils.check_run_python
|
| 32 |
+
git_clone = launch_utils.git_clone
|
| 33 |
+
git_pull_recursive = launch_utils.git_pull_recursive
|
| 34 |
+
list_extensions = launch_utils.list_extensions
|
| 35 |
+
run_extension_installer = launch_utils.run_extension_installer
|
| 36 |
+
prepare_environment = launch_utils.prepare_environment
|
| 37 |
+
configure_for_tests = launch_utils.configure_for_tests
|
| 38 |
+
start = launch_utils.start
|
| 39 |
+
|
| 40 |
+
util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py'
|
| 41 |
+
|
| 42 |
+
# 创建主程序函数
|
| 43 |
+
def main():
|
| 44 |
+
# 创建线程用于实时查找并打印链接
|
| 45 |
+
link_thread = threading.Thread(target=find_and_print_links)
|
| 46 |
+
link_thread.daemon = True # 设置为守护线程,程序退出时自动结束
|
| 47 |
+
link_thread.start()
|
| 48 |
+
|
| 49 |
+
# 主程序代码块
|
| 50 |
+
# 这里包含了原来在 if __name__ == "__main__": 中的代码
|
| 51 |
+
|
| 52 |
+
# 设置标志变量来确定是否执行主程序
|
| 53 |
+
run_main = True
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
run_main = True # 如果直接运行 launch.py,则设置为 True
|
| 57 |
+
main()
|
| 58 |
|
| 59 |
+
# 其他模块导入语句
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|