|
import subprocess |
|
import sys |
|
import logging |
|
import os |
|
|
|
|
|
log_file = '/bushu/logs_run.txt' |
|
if os.path.exists(log_file): |
|
os.remove(log_file) |
|
|
|
|
|
logging.basicConfig(filename=log_file, 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: |
|
|
|
with open(log_file, 'a') as log_file_handle: |
|
subprocess.run(['python', '/bushu/ui/launch.py', '--skip-torch-cuda-test', "--no-launch"], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT) |
|
|
|
except subprocess.CalledProcessError as e: |
|
|
|
logging.exception(f"程序发生异常: {e}") |
|
except Exception as e: |
|
|
|
logging.exception(f"程序发生异常: {e}") |
|
finally: |
|
|
|
logging.getLogger().removeHandler(console_handler) |
|
console_handler.close() |
|
|