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: launch_utils.prepare_environment() os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {launch_utils.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: launch_utils.configure_for_tests() launch_utils.start() except Exception as e: # 捕获其他异常并记录到日志文件 logging.exception(f"程序发生异常: {e}") finally: # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件 logging.getLogger().removeHandler(console_handler) console_handler.close()