Pathikreet commited on
Commit
3eb85d0
·
verified ·
1 Parent(s): 65ac9f8

Stop button: write flag file, wait 120s for clean save, fallback terminate

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- import subprocess, sys, os, threading, json, datetime
3
  import matplotlib
4
  matplotlib.use('Agg')
5
  import matplotlib.pyplot as plt
@@ -72,6 +72,17 @@ def stop_training():
72
  with _lock:
73
  if not _proc or _proc.poll() is not None:
74
  return "No training process is currently running.", *build_plots()
 
 
 
 
 
 
 
 
 
 
 
75
  _proc.terminate()
76
 
77
  m = _load_metrics() or {}
 
1
  import gradio as gr
2
+ import subprocess, sys, os, threading, json, datetime, time
3
  import matplotlib
4
  matplotlib.use('Agg')
5
  import matplotlib.pyplot as plt
 
72
  with _lock:
73
  if not _proc or _proc.poll() is not None:
74
  return "No training process is currently running.", *build_plots()
75
+ # Write flag file — train.py checks this every step and saves weights before exiting
76
+ with open('/app/stop_requested', 'w') as f:
77
+ f.write('stop')
78
+
79
+ # Wait up to 120s for train.py to save weights and exit cleanly
80
+ for _ in range(24):
81
+ time.sleep(5)
82
+ if _proc.poll() is not None:
83
+ break
84
+ else:
85
+ # Fallback: hard terminate if train.py didn't respond
86
  _proc.terminate()
87
 
88
  m = _load_metrics() or {}