Skip to content

Commit 4838ee4

Browse files
committed
[feat/1316] lint fix
1 parent b3c46d1 commit 4838ee4

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

jupyter_server/prometheus/server.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,8 @@ def periodic_update():
140140
# Run initial update
141141
periodic_update()
142142

143-
# Set up periodic updates every 30 seconds
144-
def start_periodic_updates():
145-
loop = tornado.ioloop.IOLoop.current()
146-
147-
def update():
148-
periodic_update()
149-
loop.call_later(30, update)
150-
151-
loop.call_later(30, update)
152-
153-
# Start periodic updates in the main server's IOLoop
154-
if hasattr(self.server_app, "io_loop") and self.server_app.io_loop:
155-
self.server_app.io_loop.add_callback(start_periodic_updates)
143+
# Store the periodic update function to be called from the metrics server thread
144+
self._periodic_update = periodic_update
156145

157146
def start(self, port: int) -> None:
158147
"""Start the metrics server on the specified port.
@@ -220,6 +209,17 @@ def start(self, port: int) -> None:
220209
def start_metrics_loop():
221210
loop = tornado.ioloop.IOLoop()
222211
loop.make_current()
212+
213+
# Set up periodic updates in this IOLoop
214+
def periodic_update_wrapper():
215+
if hasattr(self, '_periodic_update'):
216+
self._periodic_update()
217+
# Schedule next update in 30 seconds
218+
loop.call_later(30, periodic_update_wrapper)
219+
220+
# Start periodic updates
221+
loop.call_later(30, periodic_update_wrapper)
222+
223223
loop.start()
224224

225225
self.thread = threading.Thread(target=start_metrics_loop, daemon=True)

0 commit comments

Comments
 (0)