Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: automatic port selection (#5090)

Stefan Fuertinger88f927d9829a
diff --git a/marimo/_server/utils.py b/marimo/_server/utils.py
index 691c92d1d0..78c794ff01 100644
--- a/marimo/_server/utils.py
+++ b/marimo/_server/utils.py
@@ -45,9 +45,8 @@ def find_free_port(port: int, attempts: int = 100) -> int:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
try:
sock.settimeout(0.1)
- in_use = sock.connect_ex(("localhost", port)) == 0
- if not in_use:
- return port
+ sock.bind(("", port))
+ return port
except OSError:
LOGGER.debug(f"Port {port} is already in use")
pass