jens.luecke commited on
Commit
3ba20dc
Β·
1 Parent(s): 5f595e0

FINAL FIX: Remove demo.unload that was causing 502 errors on page reloads

Browse files
Files changed (1) hide show
  1. app.py +3 -13
app.py CHANGED
@@ -94,13 +94,6 @@ def stop_preview_app():
94
  """Stop the preview app subprocess if it's running."""
95
  global preview_process
96
  if preview_process and preview_process.poll() is None:
97
- # Add stack trace to understand what's calling this function
98
- import traceback
99
-
100
- print("πŸ” DEBUGGING: stop_preview_app() called from:")
101
- for line in traceback.format_stack()[-3:-1]: # Show last 2 stack frames
102
- print(f" {line.strip()}")
103
-
104
  print(f"πŸ›‘ Stopping preview app process (PID: {preview_process.pid})...")
105
  try:
106
  preview_process.terminate()
@@ -258,7 +251,6 @@ def create_iframe_preview():
258
 
259
  # First, check if existing process is healthy
260
  if preview_process is not None:
261
- print(f"πŸ” Found existing preview process (PID: {preview_process.pid})")
262
  healthy, status = check_preview_health()
263
  print(f"πŸ” Health check: {status}")
264
  if healthy:
@@ -266,7 +258,6 @@ def create_iframe_preview():
266
  iframe_html = (
267
  f'<iframe src="{PREVIEW_URL}" ' 'width="100%" height="500px"></iframe>'
268
  )
269
- print("πŸ” Returning iframe HTML without restart")
270
  return iframe_html
271
  else:
272
  print(f"⚠️ Preview app unhealthy: {status}, attempting restart...")
@@ -274,14 +265,12 @@ def create_iframe_preview():
274
  print("πŸ” No preview process exists, starting new one")
275
 
276
  # Try to start the preview app and show an iframe
277
- print("πŸ” About to call start_preview_app()")
278
  success, message = start_preview_app()
279
  print(f"πŸ” start_preview_app() result: success={success}, message={message}")
280
  if success:
281
  iframe_html = (
282
  f'<iframe src="{PREVIEW_URL}" ' 'width="100%" height="500px"></iframe>'
283
  )
284
- print(f"πŸ” Creating iframe: {iframe_html}")
285
  return iframe_html
286
  else:
287
  # Show a more user-friendly error message with retry option
@@ -835,8 +824,9 @@ class GradioUI:
835
  # Load the preview iframe when the app starts
836
  demo.load(fn=create_iframe_preview, outputs=[preview_html])
837
 
838
- # Clean up on app close
839
- demo.unload(stop_preview_app)
 
840
 
841
  return demo
842
 
 
94
  """Stop the preview app subprocess if it's running."""
95
  global preview_process
96
  if preview_process and preview_process.poll() is None:
 
 
 
 
 
 
 
97
  print(f"πŸ›‘ Stopping preview app process (PID: {preview_process.pid})...")
98
  try:
99
  preview_process.terminate()
 
251
 
252
  # First, check if existing process is healthy
253
  if preview_process is not None:
 
254
  healthy, status = check_preview_health()
255
  print(f"πŸ” Health check: {status}")
256
  if healthy:
 
258
  iframe_html = (
259
  f'<iframe src="{PREVIEW_URL}" ' 'width="100%" height="500px"></iframe>'
260
  )
 
261
  return iframe_html
262
  else:
263
  print(f"⚠️ Preview app unhealthy: {status}, attempting restart...")
 
265
  print("πŸ” No preview process exists, starting new one")
266
 
267
  # Try to start the preview app and show an iframe
 
268
  success, message = start_preview_app()
269
  print(f"πŸ” start_preview_app() result: success={success}, message={message}")
270
  if success:
271
  iframe_html = (
272
  f'<iframe src="{PREVIEW_URL}" ' 'width="100%" height="500px"></iframe>'
273
  )
 
274
  return iframe_html
275
  else:
276
  # Show a more user-friendly error message with retry option
 
824
  # Load the preview iframe when the app starts
825
  demo.load(fn=create_iframe_preview, outputs=[preview_html])
826
 
827
+ # Note: Removed demo.unload(stop_preview_app) as it was causing
828
+ # preview app restarts on every page reload, leading to 502 errors.
829
+ # We have proper cleanup via signal handlers and atexit handlers.
830
 
831
  return demo
832