Skip to content

Commit c42d85c

Browse files
committed
setsockopt on mac too
1 parent fb9c57f commit c42d85c

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/py/reactpy/.temp.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from reactpy import component, html, run, use_state
2+
from reactpy.core.types import State
3+
4+
5+
@component
6+
def Item(item: str, all_items: State[list[str]]):
7+
color = use_state(None)
8+
9+
def deleteme(event):
10+
all_items.set_value([i for i in all_items.value if (i != item)])
11+
12+
def colorize(event):
13+
color.set_value("blue" if not color.value else None)
14+
15+
return html.div(
16+
{"id": item, "style": {"background_color": color.value}},
17+
html.button({"on_click": colorize}, f"Color {item}"),
18+
html.button({"on_click": deleteme}, f"Delete {item}"),
19+
)
20+
21+
22+
@component
23+
def App():
24+
items = use_state(["A", "B", "C"])
25+
return html._([Item(item, items, key=item) for item in items.value])
26+
27+
28+
run(App)

src/py/reactpy/reactpy/backend/utils.py

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

0 commit comments

Comments
 (0)