-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestart.py
More file actions
38 lines (34 loc) Β· 987 Bytes
/
restart.py
File metadata and controls
38 lines (34 loc) Β· 987 Bytes
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
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import subprocess
import sys
import signal
import time
import os
def kill_existing_server():
"""Kill any existing uvicorn process on port 8000"""
try:
subprocess.run(["fuser", "-k", "8000/tcp"], stderr=subprocess.DEVNULL)
time.sleep(1)
except:
pass
def start_server():
"""Start the FastAPI server"""
print("\n" + "="*60)
print("π Starting Weather API Server")
print("="*60)
print("π Server will be available at: http://localhost:8000")
print("π In Codespaces: Open PORTS tab β Click globe icon on port 8000")
print("="*60 + "\n")
try:
subprocess.run([
sys.executable, "-m", "uvicorn",
"app:app",
"--reload",
"--host", "0.0.0.0",
"--port", "8000"
])
except KeyboardInterrupt:
print("\n\nπ Server stopped by user")
if __name__ == "__main__":
kill_existing_server()
start_server()