Skip to content

Commit 548e279

Browse files
committed
[feat/1316] test cases fix
1 parent a712519 commit 548e279

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

jupyter_server/kernelspecs/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class KernelSpecResourceHandler(web.StaticFileHandler, JupyterHandler):
1717
"""A Kernelspec resource handler."""
1818

19-
SUPPORTED_METHODS = ("GET", "HEAD") # type:ignore[assignment]
19+
SUPPORTED_METHODS = ("GET", "HEAD")
2020
auth_resource = AUTH_RESOURCE
2121

2222
def initialize(self):

jupyter_server/nbconvert/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class NbconvertFileHandler(JupyterHandler):
9090
"""An nbconvert file handler."""
9191

9292
auth_resource = AUTH_RESOURCE
93-
SUPPORTED_METHODS = ("GET",) # type:ignore[assignment]
93+
SUPPORTED_METHODS = ("GET",)
9494

9595
@web.authenticated
9696
@authorized
@@ -158,7 +158,7 @@ async def get(self, format, path):
158158
class NbconvertPostHandler(JupyterHandler):
159159
"""An nbconvert post handler."""
160160

161-
SUPPORTED_METHODS = ("POST",) # type:ignore[assignment]
161+
SUPPORTED_METHODS = ("POST",)
162162
auth_resource = AUTH_RESOURCE
163163

164164
@web.authenticated

jupyter_server/prometheus/server.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,20 @@ def start(self, port: int) -> None:
206206

207207
# Start the IOLoop in a separate thread
208208
def start_metrics_loop():
209-
loop = tornado.ioloop.IOLoop()
210-
loop.make_current()
209+
self.ioloop = tornado.ioloop.IOLoop()
210+
self.ioloop.make_current()
211211

212212
# Set up periodic updates in this IOLoop
213213
def periodic_update_wrapper():
214214
if hasattr(self, "_periodic_update"):
215215
self._periodic_update()
216216
# Schedule next update in 30 seconds
217-
loop.call_later(30, periodic_update_wrapper)
217+
self.ioloop.call_later(30, periodic_update_wrapper)
218218

219219
# Start periodic updates
220-
loop.call_later(30, periodic_update_wrapper)
220+
self.ioloop.call_later(30, periodic_update_wrapper)
221221

222-
loop.start()
222+
self.ioloop.start()
223223

224224
self.thread = threading.Thread(target=start_metrics_loop, daemon=True)
225225
self.thread.start()
@@ -234,12 +234,16 @@ def stop(self) -> None:
234234
self.http_server.stop()
235235
self.http_server = None
236236

237+
if hasattr(self, 'ioloop') and self.ioloop:
238+
# Stop the IOLoop
239+
self.ioloop.add_callback(self.ioloop.stop)
240+
self.ioloop = None
241+
237242
if self.thread and self.thread.is_alive():
238-
# Note: Tornado IOLoop doesn't have a clean stop method
239-
# The thread will exit when the process ends
240-
pass
243+
# Wait for thread to finish (with timeout)
244+
self.thread.join(timeout=1.0)
241245

242-
self.server_app.log.info(f"Metrics server stopped on port {self.port}")
246+
self.server_app.log.info(f"Metrics server stopped on port {getattr(self, 'port', 'unknown')}")
243247

244248

245249
def start_metrics_server(server_app, port: int) -> PrometheusMetricsServer:

jupyter_server/serverapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,6 @@ def start_app(self) -> None:
31463146
# Determine metrics URL based on whether separate metrics server is running
31473147
if (
31483148
self.metrics_port
3149-
and hasattr(self, "metrics_server")
31503149
and self.metrics_server is not None
31513150
and hasattr(self.metrics_server, "port")
31523151
and self.metrics_server.port is not None
@@ -3244,7 +3243,8 @@ async def _cleanup(self) -> None:
32443243
self.http_server.stop()
32453244
if hasattr(self, "metrics_server"):
32463245
# Stop the metrics server if it's running
3247-
self.metrics_server.stop()
3246+
if self.metrics_server is not None and hasattr(self.metrics_server, 'stop'):
3247+
self.metrics_server.stop()
32483248

32493249
def start_ioloop(self) -> None:
32503250
"""Start the IO Loop."""

jupyter_server/services/contents/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _validate_keys(expect_defined: bool, model: dict[str, Any], keys: list[str])
3737
f"Keys unexpectedly None: {errors}",
3838
)
3939
else:
40-
errors = {key: model[key] for key in keys if model[key] is not None} # type: ignore[assignment]
40+
errors = {key: model[key] for key in keys if model[key] is not None}
4141
if errors:
4242
raise web.HTTPError(
4343
500,

0 commit comments

Comments
 (0)