pgits Claude commited on
Commit
45ef56e
·
1 Parent(s): af2b4ec

Fix application multiple restart issue on HuggingFace Spaces

Browse files

- Add 2-second startup delay to prevent rapid restart loops
- Disable reload mode for production stability
- Set single worker mode for HF Spaces environment
- Reduce uvicorn log noise with warning level

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -47,12 +47,18 @@ if __name__ == "__main__":
47
  logger.debug(f" {var}: {masked}")
48
 
49
  try:
 
 
 
 
50
  uvicorn.run(
51
  app,
52
  host="0.0.0.0",
53
  port=port,
54
  log_level="warning", # Reduce uvicorn noise, our dual logger handles app logs
55
- access_log=False # Reduce access log spam
 
 
56
  )
57
  except Exception as e:
58
  logger.critical(f"💥 Application startup failed: {e}")
 
47
  logger.debug(f" {var}: {masked}")
48
 
49
  try:
50
+ # Add startup delay to prevent rapid restart loops
51
+ import time
52
+ time.sleep(2) # Give HF Spaces time to stabilize
53
+
54
  uvicorn.run(
55
  app,
56
  host="0.0.0.0",
57
  port=port,
58
  log_level="warning", # Reduce uvicorn noise, our dual logger handles app logs
59
+ access_log=False, # Reduce access log spam
60
+ reload=False, # Never use reload in production
61
+ workers=1 # Single worker for HF Spaces
62
  )
63
  except Exception as e:
64
  logger.critical(f"💥 Application startup failed: {e}")