-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.py
More file actions
35 lines (28 loc) · 958 Bytes
/
run.py
File metadata and controls
35 lines (28 loc) · 958 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
import subprocess
import time
import webbrowser
HOST = "0.0.0.0"
PORT = 5000
def open_browser():
"""Opens the web browser to the application."""
print(f"Opening browser to http://127.0.0.1:{PORT}")
webbrowser.open_new(f"http://127.0.0.1:{PORT}")
if __name__ == "__main__":
print("Starting production server with Waitress...")
# Start the Waitress server as a subprocess
server_process = subprocess.Popen(
["waitress-serve", f"--host={HOST}", f"--port={PORT}", "app:app"]
)
# Give the server a moment to start up
time.sleep(2)
# Open the web browser
open_browser()
try:
# Wait for the server process to complete.
# You can press Ctrl+C in this window to stop the server.
server_process.wait()
except KeyboardInterrupt:
print("Stopping server...")
server_process.terminate()
server_process.wait()
print("Server stopped.")