Skip to content

Commit cfb0c24

Browse files
committed
Added find_port.py
1 parent bed1b0c commit cfb0c24

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

Diff for: pages/not_found_404.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def NotFoundPage():
1414
html.img({'alt': '404 not found', 'class_name': 'img-fluid w-75', 'src': 'static/images/404.svg'}),
1515
html.h1({'class_name': 'text-4xl font-bold mt-5'},"Page not found"),
1616
html.p({'class_name': 'text-xl m-5'}, "Oops! Looks like you followed a bad link. If you think this is a problem with us, please tell us."),
17-
link(ButtonWithIcon("Back to homepage", Icon_BackArrow), to='/products')
17+
link(ButtonWithIcon("Back to homepage", Icon_BackArrow), to='/')
1818
)
1919
)
2020
)

Diff for: poetry.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fastapi = "0.96.0"
1313
uvicorn = "0.22.0"
1414
pydantic = " 1.10.13"
1515
reactpy-apexcharts = "0.0.9"
16-
reactpy-github-buttons = "0.0.11"
16+
reactpy-github-buttons = "0.0.12"
1717
reactpy-router = {url = "https://raw.githubusercontent.com/stevej2608/reactpy-router/master/dist/reactpy_router-0.1.1-py2.py3-none-any.whl"}
1818

1919
[tool.poetry.group.dev.dependencies]

Diff for: run_dashboard.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from pages.app_main import AppMain
22
from fast_server import run
3+
from utils.find_port import find_available_port
34

45
# python run_dashboard.py
56

67
if __name__ == "__main__":
7-
run(AppMain, disable_server_logs=True)
8+
port = find_available_port()
9+
run(AppMain, port=port, disable_server_logs=True)

Diff for: utils/find_port.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import socket
2+
import sys
3+
from contextlib import closing
4+
5+
6+
def find_available_port(host: str = 'localhost', port_min: int = 8000, port_max: int = 9000) -> int:
7+
"""Get a port that's available for the given host and port range"""
8+
for port in range(port_min, port_max):
9+
with closing(socket.socket()) as sock:
10+
try:
11+
if sys.platform in ("linux", "darwin"):
12+
# Fixes bug on Unix-like systems where every time you restart the
13+
# server you'll get a different port on Linux. This cannot be set
14+
# on Windows otherwise address will always be reused.
15+
# Ref: https://stackoverflow.com/a/19247688/3159288
16+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
17+
sock.bind((host, port))
18+
except OSError:
19+
pass
20+
else:
21+
return port
22+
msg = f"Host {host!r} has no available port in range {port_max}-{port_max}"
23+
raise RuntimeError(msg)

0 commit comments

Comments
 (0)