File size: 1,699 Bytes
9aa83d4
 
 
 
e32aff8
 
 
afd65b5
 
 
 
 
 
 
 
 
e32aff8
afd65b5
 
9cefd9a
 
afd65b5
9cefd9a
 
 
 
 
 
 
 
 
 
 
 
 
e32aff8
 
 
afd65b5
e32aff8
 
f1b9988
7452a8e
f1b9988
afd65b5
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from modules import launch_utils
import os
import subprocess
import threading
import logging
import sys

# 设置启动参数
args = launch_utils.args
args.listen = True
args.xformers = True
args.enable_insecure_extension_access = True
args.theme = "dark"
args.gradio_queue = True
args.multiple = True
args.no_download_sd_model = True

# 设置日志文件路径
log_file_path = '/bushu/logs_run.txt'

# 配置日志
logging.basicConfig(filename=log_file_path, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# 创建一个将输出同时发送到控制台和日志文件的处理程序
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
console_handler.setFormatter(formatter)
logging.getLogger().addHandler(console_handler)

# 重定向标准输出和标准错误到日志文件和控制台
sys.stdout = logging.getLogger().handlers[0].stream
sys.stderr = logging.getLogger().handlers[0].stream

try:
    if not args.skip_prepare_environment:
        prepare_environment()
        os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
        os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")

    if args.test_server:
        configure_for_tests()

    start()
except Exception as e:
    # 捕获其他异常并记录到日志文件
    logging.exception(f"程序发生异常: {e}")
finally:
    # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
    logging.getLogger().removeHandler(console_handler)
    console_handler.close()