setsockopt on mac too

This commit is contained in:
Ryan Morshead 2023-07-23 22:52:28 -06:00
parent fb9c57f073
commit c42d85c292
2 changed files with 32 additions and 4 deletions

28
src/py/reactpy/.temp.py Normal file
View file

@ -0,0 +1,28 @@
from reactpy import component, html, run, use_state
from reactpy.core.types import State
@component
def Item(item: str, all_items: State[list[str]]):
color = use_state(None)
def deleteme(event):
all_items.set_value([i for i in all_items.value if (i != item)])
def colorize(event):
color.set_value("blue" if not color.value else None)
return html.div(
{"id": item, "style": {"background_color": color.value}},
html.button({"on_click": colorize}, f"Color {item}"),
html.button({"on_click": deleteme}, f"Delete {item}"),
)
@component
def App():
items = use_state(["A", "B", "C"])
return html._([Item(item, items, key=item) for item in items.value])
run(App)

View file

@ -53,10 +53,10 @@ def find_available_port(host: str, port_min: int = 8000, port_max: int = 9000) -
for port in range(port_min, port_max):
with closing(socket.socket()) as sock:
try:
if sys.platform == "linux":
# Fixes bug where every time you restart the server you'll
# get a different port on Linux. This cannot be set on Windows
# otherwise address will always be reused.
if sys.platform in ("linux", "darwin"):
# Fixes bug on Unix-like systems where every time you restart the
# server you'll get a different port on Linux. This cannot be set
# on Windows otherwise address will always be reused.
# Ref: https://stackoverflow.com/a/19247688/3159288
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))