-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_app2.py
More file actions
executable file
·29 lines (25 loc) · 1.26 KB
/
run_app2.py
File metadata and controls
executable file
·29 lines (25 loc) · 1.26 KB
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
26
27
28
29
import os
os.environ["APP_LOG_LEVEL"] = "INFO" # Set app-specific log level for development
from papers2code_app2 import main
import uvicorn
import logging
import sys
import signal
def handle_exit(signum, frame):
print("Exit signal received, shutting down gracefully...")
sys.exit(0)
if __name__ == "__main__":
# Register signal handlers for graceful shutdown
signal.signal(signal.SIGINT, handle_exit) # Handles Ctrl+C
signal.signal(signal.SIGTERM, handle_exit) # Handles termination signal
try:
print("Starting Papers2Code FastAPI application...")
print("API documentation will be available at http://localhost:/docs")
print(f"Application log level set by run_app2.py to: {os.getenv('APP_LOG_LEVEL')}") # Confirm APP_LOG_LEVEL
print("The application uses FastAPI lifespan events for startup/shutdown handling")
print("Press Ctrl+C to stop the server and trigger shutdown events")
# The log_level here controls Uvicorn's server logs, not the application logger defined in main.py
uvicorn.run(main.app, host="0.0.0.0", port=5001, log_level="info")
except Exception as e:
logging.error(f"Failed to start application: {e}", exc_info=True)
sys.exit(1)