File size: 1,416 Bytes
4c60780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()