diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 979f3ab452..54c169eed9 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -558,7 +558,7 @@ def _maybe_remove_unix_socket(socket_path): pass def start(self): - servers = list(list_running_servers(self.runtime_dir)) + servers = list(list_running_servers(self.runtime_dir, log=self.log)) if not servers: self.exit("There are no running servers (per %s)" % self.runtime_dir) for server in servers: @@ -619,7 +619,7 @@ class JupyterServerListApp(JupyterApp): ) def start(self): - serverinfo_list = list(list_running_servers(self.runtime_dir)) + serverinfo_list = list(list_running_servers(self.runtime_dir, log=self.log)) if self.jsonlist: print(json.dumps(serverinfo_list, indent=2)) elif self.json: @@ -2682,7 +2682,7 @@ def stop(self, from_signal=False): self.io_loop.add_callback(self._stop) -def list_running_servers(runtime_dir=None): +def list_running_servers(runtime_dir=None, log=None): """Iterate over the server info files of running Jupyter servers. Given a runtime directory, find jpserver-* files in the security directory, @@ -2709,8 +2709,9 @@ def list_running_servers(runtime_dir=None): # If the process has died, try to delete its info file try: os.unlink(os.path.join(runtime_dir, file_name)) - except OSError: - pass # TODO: This should warn or log or something + except OSError as e: + if log: + log.warning(_i18n("Deleting server info file failed: %s.") % e) # ----------------------------------------------------------------------------- diff --git a/jupyter_server/services/kernels/handlers.py b/jupyter_server/services/kernels/handlers.py index 6e4d6989f3..f3c5cd0f66 100644 --- a/jupyter_server/services/kernels/handlers.py +++ b/jupyter_server/services/kernels/handlers.py @@ -5,7 +5,6 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import json -import logging from textwrap import dedent from ipython_genutils.py3compat import cast_unicode @@ -624,11 +623,11 @@ def _send_status_message(self, status): self.write_message(json.dumps(msg, default=json_default)) def on_kernel_restarted(self): - logging.warn("kernel %s restarted", self.kernel_id) + self.log.warning("kernel %s restarted", self.kernel_id) self._send_status_message("restarting") def on_restart_failed(self): - logging.error("kernel %s restarted failed!", self.kernel_id) + self.log.error("kernel %s restarted failed!", self.kernel_id) self._send_status_message("dead") def _on_error(self, msg):