Spaces:
Sleeping
Sleeping
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
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 |
-
#
|
| 839 |
-
|
|
|
|
| 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 |
|