Skip to content

Commit 8709698

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

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

jupyter_server/prometheus/server.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def initialize_metrics(self):
7575
LAST_ACTIVITY.set_function(lambda: self.app.web_app.last_activity().timestamp())
7676
ACTIVE_DURATION.set_function(
7777
lambda: (
78-
self.app.web_app.last_activity()
79-
- self.app.web_app.settings["started"]
78+
self.app.web_app.last_activity() - self.app.web_app.settings["started"]
8079
).total_seconds()
8180
)
8281

@@ -152,13 +151,15 @@ def start(self, port: int = 9090) -> None:
152151
self.initialize_metrics()
153152

154153
# Create Tornado application with metrics handler
155-
app = tornado.web.Application([
156-
(r"/metrics", PrometheusMetricsHandler),
157-
])
154+
app = tornado.web.Application(
155+
[
156+
(r"/metrics", PrometheusMetricsHandler),
157+
]
158+
)
158159

159160
# Create HTTP server
160161
self.server = tornado.httpserver.HTTPServer(app)
161-
162+
162163
# Try to bind to the specified port
163164
try:
164165
self.server.bind(port)
@@ -178,7 +179,7 @@ def start(self, port: int = 9090) -> None:
178179
# Start the server in a separate thread
179180
self.thread = threading.Thread(target=self._start_metrics_loop, daemon=True)
180181
self.thread.start()
181-
182+
182183
# Wait for server to be ready
183184
self._wait_for_server_ready()
184185
self._running = True
@@ -188,23 +189,23 @@ def _start_metrics_loop(self) -> None:
188189
try:
189190
# Create a new IOLoop for this thread
190191
self.ioloop = tornado.ioloop.IOLoop()
191-
192+
192193
# Set as current event loop for this thread
193194
asyncio.set_event_loop(self.ioloop.asyncio_loop)
194-
195+
195196
# Start the server
196197
self.server.start(1) # Single process
197-
198+
198199
# Set up periodic updates in this IOLoop
199200
def periodic_update_wrapper():
200201
if hasattr(self, "_periodic_update"):
201202
self._periodic_update()
202203
# Schedule next update in 30 seconds
203204
self.ioloop.call_later(30, periodic_update_wrapper)
204-
205+
205206
# Start periodic updates
206207
self.ioloop.call_later(30, periodic_update_wrapper)
207-
208+
208209
# Start the IOLoop
209210
self.ioloop.start()
210211
except Exception as e:
@@ -218,9 +219,9 @@ def _wait_for_server_ready(self, timeout: float = 5.0) -> None:
218219
try:
219220
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
220221
s.settimeout(0.1)
221-
s.connect(('localhost', self.port))
222+
s.connect(("localhost", self.port))
222223
return
223-
except (socket.error, OSError):
224+
except OSError:
224225
time.sleep(0.1)
225226
raise TimeoutError(f"Server not ready after {timeout} seconds")
226227

0 commit comments

Comments
 (0)