BBrother commited on
Commit
19843be
·
1 Parent(s): 5265919

Update SW_run.py

Browse files
Files changed (1) hide show
  1. SW_run.py +44 -53
SW_run.py CHANGED
@@ -1,56 +1,47 @@
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
- args = launch_utils.args
11
- args.listen = True
12
- args.xformers = True
13
- args.enable_insecure_extension_access = True
14
- args.theme = "dark"
15
- args.gradio_queue = True
16
- args.multiple = True
17
- args.no_download_sd_model = True
18
- args.share = True -o /bushu/out_url.txt
19
-
20
- args = launch_utils.args
21
- python = launch_utils.python
22
- git = launch_utils.git
23
- index_url = launch_utils.index_url
24
- dir_repos = launch_utils.dir_repos
25
-
26
- commit_hash = launch_utils.commit_hash
27
- git_tag = launch_utils.git_tag
28
-
29
- run = launch_utils.run
30
- is_installed = launch_utils.is_installed
31
- repo_dir = launch_utils.repo_dir
32
-
33
- run_pip = launch_utils.run_pip
34
- check_run_python = launch_utils.check_run_python
35
- git_clone = launch_utils.git_clone
36
- git_pull_recursive = launch_utils.git_pull_recursive
37
- list_extensions = launch_utils.list_extensions
38
- run_extension_installer = launch_utils.run_extension_installer
39
- prepare_environment = launch_utils.prepare_environment
40
- configure_for_tests = launch_utils.configure_for_tests
41
- start = launch_utils.start
42
-
43
-
44
- def main():
45
- if not args.skip_prepare_environment:
46
- prepare_environment()
47
- os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
48
- os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")
49
-
50
- if args.test_server:
51
- configure_for_tests()
52
-
53
- start()
54
-
55
-
56
- main()
 
 
 
1
  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
+
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
+ try:
26
+ # 在try块中运行 /bushu/ui/launch.py,并将输出重定向到日志文件
27
+ with open(log_file, 'a') as log_file_handle:
28
+ process = subprocess.Popen(['python', '/bushu/ui/launch.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
29
+
30
+ # 保存包含"Running"的行到url.txt
31
+ with open('/bushu/url.txt', 'a') as url_file:
32
+ for line in process.stdout:
33
+ if "Running" in line:
34
+ url_file.write(line)
35
+ print(line, end='') # 输出包含"Running"的行到控制台
36
+ log_file_handle.write(line)
37
+ process.wait() # 等待子进程完成
38
+ except subprocess.CalledProcessError as e:
39
+ # 捕获异常并记录到日志文件
40
+ logging.exception(f"程序发生异常: {e}")
41
+ except Exception as e:
42
+ # 捕获其他异常并记录到日志文件
43
+ logging.exception(f"程序发生异常: {e}")
44
+ finally:
45
+ # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
46
+ logging.getLogger().removeHandler(console_handler)
47
+ console_handler.close()