BBrother commited on
Commit
7c519cb
1 Parent(s): 1fc0753

Update no_logs_launch.py

Browse files
Files changed (1) hide show
  1. no_logs_launch.py +69 -16
no_logs_launch.py CHANGED
@@ -5,6 +5,7 @@ import threading
5
  import logging
6
  import sys
7
 
 
8
  # 检查是否存在 logs_run.txt 文件,如果存在则删除它
9
  log_file = '/bushu/logs_run.txt'
10
  if os.path.exists(log_file):
@@ -24,6 +25,24 @@ logging.getLogger().addHandler(console_handler)
24
  sys.stdout = logging.getLogger().handlers[0].stream
25
  sys.stderr = logging.getLogger().handlers[0].stream
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # 设置启动参数
28
  args = launch_utils.args
29
  args.listen = True
@@ -35,15 +54,59 @@ args.multiple = True
35
  args.no_download_sd_model = True
36
  args.share = True
37
 
38
- # 其他设置...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py'
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def main():
42
  if not args.skip_prepare_environment:
43
  prepare_environment()
44
- for _ in range(3):
45
- os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
46
- os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
 
 
 
47
 
48
  if args.test_server:
49
  configure_for_tests()
@@ -62,21 +125,11 @@ def find_and_print_links():
62
  log_file.write(line)
63
  log_file.flush()
64
 
65
- # 打开日志文件以写入程序的所有输出
66
- log_file_path = '/bushu/logs_run_launch.txt'
67
- log_file = open(log_file_path, 'w')
68
-
69
- # 使用tee命令将程序的输出同时写入日志文件和进程管道
70
- tee_command = f"{python} -u -m tee -a {log_file_path}"
71
- log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
72
-
73
- __name__ = "__main__"
74
-
75
  main()
76
 
77
-
78
  # 等待程序执行完毕
79
  log_process.wait()
80
 
81
  # 关闭日志文件
82
- log_file.close()
 
5
  import logging
6
  import sys
7
 
8
+
9
  # 检查是否存在 logs_run.txt 文件,如果存在则删除它
10
  log_file = '/bushu/logs_run.txt'
11
  if os.path.exists(log_file):
 
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
48
  args.listen = 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
60
+ dir_repos = launch_utils.dir_repos
61
+
62
+ commit_hash = launch_utils.commit_hash
63
+ git_tag = launch_utils.git_tag
64
+
65
+ run = launch_utils.run
66
+ is_installed = launch_utils.is_installed
67
+ repo_dir = launch_utils.repo_dir
68
+
69
+ run_pip = launch_utils.run_pip
70
+ check_run_python = launch_utils.check_run_python
71
+ git_clone = launch_utils.git_clone
72
+ git_pull_recursive = launch_utils.git_pull_recursive
73
+ list_extensions = launch_utils.list_extensions
74
+ run_extension_installer = launch_utils.run_extension_installer
75
+ 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' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
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()
 
125
  log_file.write(line)
126
  log_file.flush()
127
 
128
+ # 调用 main() 函数,不再需要条件判断
 
 
 
 
 
 
 
 
 
129
  main()
130
 
 
131
  # 等待程序执行完毕
132
  log_process.wait()
133
 
134
  # 关闭日志文件
135
+ log_file.close()