Skip to content

Commit 7971ec5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e05d3e5 commit 7971ec5

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

jupyter_server/prometheus/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ def start(self, port: int) -> None:
184184

185185
# Create and start the HTTP server with port retry logic
186186
self.http_server = tornado.httpserver.HTTPServer(metrics_app)
187-
187+
188188
# Try to bind to the requested port, with fallback to random ports
189189
actual_port = port
190190
max_retries = 10
191-
191+
192192
for attempt in range(max_retries):
193193
try:
194194
self.http_server.listen(actual_port)
@@ -199,11 +199,12 @@ def start(self, port: int) -> None:
199199
if attempt == 0:
200200
# First attempt failed, try random ports
201201
import random
202+
202203
actual_port = random.randint(49152, 65535) # Use dynamic port range
203204
else:
204205
# Subsequent attempts, try next random port
205206
actual_port = random.randint(49152, 65535)
206-
207+
207208
if attempt == max_retries - 1:
208209
# Last attempt failed
209210
self.server_app.log.warning(

jupyter_server/serverapp.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,12 +3053,16 @@ def _start_metrics_server(self, port):
30533053
try:
30543054
self.metrics_server = start_metrics_server(self, port)
30553055
# Check if the metrics server actually started (has a port)
3056-
if not hasattr(self.metrics_server, 'port') or self.metrics_server.port is None:
3056+
if not hasattr(self.metrics_server, "port") or self.metrics_server.port is None:
30573057
self.metrics_server = None
3058-
self.log.warning("Metrics server failed to start. Metrics will be available on the main server at /metrics")
3058+
self.log.warning(
3059+
"Metrics server failed to start. Metrics will be available on the main server at /metrics"
3060+
)
30593061
except Exception as e:
30603062
self.metrics_server = None
3061-
self.log.warning(f"Failed to start metrics server: {e}. Metrics will be available on the main server at /metrics")
3063+
self.log.warning(
3064+
f"Failed to start metrics server: {e}. Metrics will be available on the main server at /metrics"
3065+
)
30623066

30633067
def launch_browser(self) -> None:
30643068
"""Launch the browser."""
@@ -3135,11 +3139,13 @@ def start_app(self) -> None:
31353139
# with auth info.
31363140

31373141
# Determine metrics URL based on whether separate metrics server is running
3138-
if (self.metrics_port and
3139-
hasattr(self, 'metrics_server') and
3140-
self.metrics_server is not None and
3141-
hasattr(self.metrics_server, 'port') and
3142-
self.metrics_server.port is not None):
3142+
if (
3143+
self.metrics_port
3144+
and hasattr(self, "metrics_server")
3145+
and self.metrics_server is not None
3146+
and hasattr(self.metrics_server, "port")
3147+
and self.metrics_server.port is not None
3148+
):
31433149
# Separate metrics server is running
31443150
if self.authenticate_prometheus:
31453151
metrics_url = f"http://localhost:{self.metrics_server.port}/metrics?token={self.identity_provider.token}"

0 commit comments

Comments
 (0)