-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
32 lines (25 loc) · 923 Bytes
/
Copy pathrun.py
File metadata and controls
32 lines (25 loc) · 923 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
# run.py
# Launcher that finds a free port then starts the Streamlit dashboard.
#
# Usage: python run.py
import socket
import subprocess
import sys
START_PORT = 8501
END_PORT = 8600
def find_free_port(start: int, end: int) -> int:
"""Return the first port in range that nothing is listening on."""
for port in range(start, end + 1):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# If connect fails, the port is free
if s.connect_ex(("localhost", port)) != 0:
return port
raise RuntimeError(f"No free port found between {start} and {end}")
if __name__ == "__main__":
port = find_free_port(START_PORT, END_PORT)
print(f"Starting dashboard on http://localhost:{port}")
subprocess.run([
sys.executable, "-m", "streamlit", "run", "dashboard.py",
"--server.port", str(port),
"--server.headless", "true",
])