Update no_logs_launch.py
Browse files- no_logs_launch.py +12 -87
no_logs_launch.py
CHANGED
|
@@ -1,47 +1,10 @@
|
|
| 1 |
-
from modules import launch_utils
|
| 2 |
import os
|
| 3 |
-
import subprocess
|
| 4 |
-
import threading
|
| 5 |
-
import logging
|
| 6 |
import sys
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
if os.path.exists(log_file):
|
| 12 |
-
os.remove(log_file)
|
| 13 |
-
|
| 14 |
-
# 配置日志
|
| 15 |
-
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 16 |
-
|
| 17 |
-
# 创建一个将输出同时发送到控制台和日志文件的处理程序
|
| 18 |
-
console_handler = logging.StreamHandler(sys.stdout)
|
| 19 |
-
console_handler.setLevel(logging.INFO)
|
| 20 |
-
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
| 21 |
-
console_handler.setFormatter(formatter)
|
| 22 |
-
logging.getLogger().addHandler(console_handler)
|
| 23 |
-
|
| 24 |
-
# 重定向标准输出和标准错误到日志文件和控制台
|
| 25 |
-
sys.stdout = logging.getLogger().handlers[0].stream
|
| 26 |
-
sys.stderr = logging.getLogger().handlers[0].stream
|
| 27 |
-
|
| 28 |
-
# 切换到/bushu/ui目录
|
| 29 |
-
subprocess.run(["cd", "/bushu/ui"], shell=True)
|
| 30 |
-
|
| 31 |
-
try:
|
| 32 |
-
# 在try块中运行v2_3.py,并将输出重定向到日志文件
|
| 33 |
-
with open(log_file, 'a') as log_file_handle:
|
| 34 |
-
subprocess.run(['python', '/bushu/ui/launch.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
|
| 35 |
-
except subprocess.CalledProcessError as e:
|
| 36 |
-
# 捕获异常并记录到日志文件
|
| 37 |
-
logging.exception(f"程序发生异常: {e}")
|
| 38 |
-
except Exception as e:
|
| 39 |
-
# 捕获其他异常并记录到日志文件
|
| 40 |
-
logging.exception(f"程序发生异常: {e}")
|
| 41 |
-
finally:
|
| 42 |
-
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
| 43 |
-
logging.getLogger().removeHandler(console_handler)
|
| 44 |
-
console_handler.close()
|
| 45 |
|
| 46 |
# 设置启动参数
|
| 47 |
args = launch_utils.args
|
|
@@ -52,8 +15,10 @@ args.theme = "dark"
|
|
| 52 |
args.gradio_queue = True
|
| 53 |
args.multiple = True
|
| 54 |
args.no_download_sd_model = True
|
| 55 |
-
args.share = True
|
| 56 |
|
|
|
|
|
|
|
|
|
|
| 57 |
python = launch_utils.python
|
| 58 |
git = launch_utils.git
|
| 59 |
index_url = launch_utils.index_url
|
|
@@ -76,60 +41,20 @@ prepare_environment = launch_utils.prepare_environment
|
|
| 76 |
configure_for_tests = launch_utils.configure_for_tests
|
| 77 |
start = launch_utils.start
|
| 78 |
|
| 79 |
-
util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py'
|
| 80 |
-
|
| 81 |
-
# 打开日志文件以写入程序的所有输出
|
| 82 |
-
log_file_path = '/bushu/logs_run_launch.txt'
|
| 83 |
-
log_file = open(log_file_path, 'w')
|
| 84 |
-
|
| 85 |
-
# 创建一个线程,用于实时查找并打印链接
|
| 86 |
-
def find_and_print_links():
|
| 87 |
-
while True:
|
| 88 |
-
line = log_process.stdout.readline()
|
| 89 |
-
if "Public WebUI Colab URL" in line:
|
| 90 |
-
url = line.split("Public WebUI Colab URL: ")[1].strip()
|
| 91 |
-
print(url) # 在控制台中显示链接
|
| 92 |
-
else:
|
| 93 |
-
# 将其他消息记录到日志文件
|
| 94 |
-
log_file.write(line)
|
| 95 |
-
log_file.flush()
|
| 96 |
-
|
| 97 |
-
# 使用tee命令将程序的输出同时写入日志文件和进程管道
|
| 98 |
-
tee_command = f"{python} -u -m tee -a {log_file_path}"
|
| 99 |
-
log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
|
| 100 |
|
| 101 |
def main():
|
| 102 |
if not args.skip_prepare_environment:
|
| 103 |
prepare_environment()
|
| 104 |
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
| 105 |
-
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /
|
| 106 |
-
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
| 107 |
-
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
| 108 |
-
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
| 109 |
-
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
| 110 |
|
| 111 |
if args.test_server:
|
| 112 |
configure_for_tests()
|
| 113 |
|
| 114 |
start()
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
while True:
|
| 119 |
-
line = log_process.stdout.readline()
|
| 120 |
-
if "Public WebUI Colab URL" in line:
|
| 121 |
-
url = line.split("Public WebUI Colab URL: ")[1].strip()
|
| 122 |
-
print(url) # 在控制台中显示链接
|
| 123 |
-
else:
|
| 124 |
-
# 将其他消息记录到日志文件
|
| 125 |
-
log_file.write(line)
|
| 126 |
-
log_file.flush()
|
| 127 |
-
|
| 128 |
-
# 调用 main() 函数,不再需要条件判断
|
| 129 |
-
main()
|
| 130 |
-
|
| 131 |
-
# 等待程序执行完毕
|
| 132 |
-
log_process.wait()
|
| 133 |
|
| 134 |
-
#
|
| 135 |
-
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
| 2 |
import sys
|
| 3 |
+
from modules import launch_utils
|
| 4 |
|
| 5 |
+
# 重定向标准输出到空文件
|
| 6 |
+
null_file = open(os.devnull, 'w')
|
| 7 |
+
sys.stdout = null_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# 设置启动参数
|
| 10 |
args = launch_utils.args
|
|
|
|
| 15 |
args.gradio_queue = True
|
| 16 |
args.multiple = True
|
| 17 |
args.no_download_sd_model = True
|
|
|
|
| 18 |
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
args = launch_utils.args
|
| 22 |
python = launch_utils.python
|
| 23 |
git = launch_utils.git
|
| 24 |
index_url = launch_utils.index_url
|
|
|
|
| 41 |
configure_for_tests = launch_utils.configure_for_tests
|
| 42 |
start = launch_utils.start
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def main():
|
| 46 |
if not args.skip_prepare_environment:
|
| 47 |
prepare_environment()
|
| 48 |
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
| 49 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
if args.test_server:
|
| 52 |
configure_for_tests()
|
| 53 |
|
| 54 |
start()
|
| 55 |
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# 恢复标准输出
|
| 60 |
+
sys.stdout = sys.__stdout__
|