File size: 1,118 Bytes
d65fc2e | 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 | # Kernel cell (piped to `colab exec`): installs pip deps, starts phase3.py detached if it is not running, then prints the
# latest log line once a minute until it ends, so Colab sees a busy kernel for the whole job (one GPU job at a time).
import os
import subprocess
import time
LOG = "/content/set5/logs/phase3.log"
os.makedirs("/content/set5/logs", exist_ok=True)
def running():
return subprocess.run(["pgrep", "-f", "python phase3.py"], capture_output=True).returncode == 0
if not running():
subprocess.run("pip install -q diffusers timm torchdiffeq h5py >> /content/set5/logs/pip.log 2>&1", shell=True)
subprocess.Popen(f"cd /content/set5/code && nohup python phase3.py >> {LOG} 2>&1 &", shell=True)
time.sleep(15)
while running():
last = subprocess.run(f"tail -n 1 {LOG}", shell=True, capture_output=True, text=True).stdout.strip()
print(time.strftime("%H:%M:%S"), last[:160], flush=True)
time.sleep(60)
print(time.strftime("%H:%M:%S"), "PHASE3 PROCESS ENDED", flush=True)
print(subprocess.run(f"tail -n 15 {LOG}", shell=True, capture_output=True, text=True).stdout, flush=True)
|