| import subprocess | |
| import sys | |
| import time | |
| import os | |
| def run_webui(): | |
| user_args = sys.argv[1:] | |
| python_exe = "/content/venv/GUTRIS1/bin/python3.10" | |
| command = [python_exe, "launch.py"] + user_args | |
| attempt = 1 | |
| while True: | |
| print(f"\nπ [{attempt}νμ°¨] WebUI μ€ν μλ...") | |
| process = subprocess.Popen( | |
| command, | |
| env=os.environ.copy(), | |
| cwd="/content/stable-diffusion-webui-reForge" | |
| ) | |
| try: | |
| # νλ‘μΈμ€κ° λλ λκΉμ§ λκΈ° | |
| return_code = process.wait() | |
| if return_code != 0: | |
| print(f"\nβ μλ¬ λ°μ (Exit Code: {return_code}). 2μ΄ ν μλ μ¬μμ...") | |
| attempt += 1 | |
| time.sleep(2) | |
| continue | |
| else: | |
| print("\nβ WebUI μ μ μ’ λ£.") | |
| break | |
| except KeyboardInterrupt: | |
| # μ¬μ©μκ° Ctrl+Cλ₯Ό λλ μ λ | |
| print("\n\nπ μ¬μ©μκ° μ€λ¨ μ νΈλ₯Ό 보λμ΅λλ€. μμ νκ² μ’ λ£ν©λλ€...") | |
| process.terminate() # μμ νλ‘μΈμ€(WebUI)λ κ°μ΄ μ£½μ¬μ€ | |
| try: | |
| process.wait(timeout=5) | |
| except: | |
| process.kill() | |
| print("β WebUI μ’ λ£ μλ£.") | |
| break # 루ν νμΆ | |
| if __name__ == "__main__": | |
| run_webui() | |