Skip to content

Commit 07c7643

Browse files
committed
Tweak autoreload port logic
1 parent 73c3b71 commit 07c7643

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

shiny/_main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,14 @@ def run_app(
210210
run_app("myapp:my_app", app_dir="..")
211211
"""
212212

213-
# TODO: If port is 0, randomize
213+
# If port is 0, randomize
214214
if port == 0:
215215
port = _utils.random_port(host=host)
216+
# If autoreload port is calculated relative to
216217
if reload and (
217-
autoreload_port.startswith("+")
218-
or autoreload_port.startswith("-")
219-
or int(autoreload_port) == 0
218+
autoreload_port.startswith("+") or autoreload_port.startswith("-")
220219
):
221-
autoreload_port = str(_utils.random_port(host=host))
220+
autoreload_port = "0"
222221

223222
os.environ["SHINY_HOST"] = host
224223
os.environ["SHINY_PORT"] = str(port)
@@ -243,12 +242,16 @@ def run_app(
243242
"Error: Couldn't understand the provided value for --autoreload-port\n"
244243
)
245244
exit(1)
245+
autoreload_port = str(_utils.random_port(host=host))
246246
autoreload_port_num = int(m.group(2))
247247
if m.group(1) == "+":
248248
autoreload_port_num += port
249249
elif m.group(1) == "-":
250250
autoreload_port_num = port - autoreload_port_num
251251

252+
if autoreload_port_num == 0:
253+
autoreload_port_num = _utils.random_port(host=host)
254+
252255
if autoreload_port_num == port:
253256
sys.stderr.write(
254257
"Autoreload port is already being used by the app; disabling autoreload\n"

0 commit comments

Comments
 (0)