Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Oct 2, 2024
1 parent 9109cc8 commit d17c77f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
8 changes: 4 additions & 4 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ async def _handle_event(self):
for _ in range(n_events):
event_f = self._events.popleft()
event_f()
except Exception as e:
except Exception:
if self.thread.__stop.is_set():
return
raise e
raise

def _setup_pipe_in(self):
"""setup listening pipe for IOPub from forked subprocesses"""
Expand Down Expand Up @@ -202,10 +202,10 @@ async def _handle_pipe_msgs(self):
try:
while True:
await self._handle_pipe_msg()
except Exception as e:
except Exception:
if self.thread.__stop.is_set():
return
raise e
raise

async def _handle_pipe_msg(self, msg=None):
"""handle a pipe message from a subprocess"""
Expand Down
18 changes: 8 additions & 10 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ async def process_control(self):
try:
while True:
await self.process_control_message()
except BaseException as e:
except BaseException:
if self.control_stop.is_set():
return
raise e
raise

async def process_control_message(self, msg=None):
"""dispatch control requests"""
Expand Down Expand Up @@ -392,10 +392,10 @@ async def shell_channel_thread_main(self):
socket.send_multipart(msg, copy=False)
except Exception:
self.log.error("Invalid message", exc_info=True) # noqa: G201
except BaseException as e:
except BaseException:
if self.shell_stop.is_set():
return
raise e
raise

async def shell_main(self, subshell_id: str | None):
"""Main loop for a single subshell."""
Expand Down Expand Up @@ -426,10 +426,10 @@ async def process_shell(self, socket=None):
try:
while True:
await self.process_shell_message(socket=socket)
except BaseException as e:
except BaseException:
if self.shell_stop.is_set():
return
raise e
raise

async def process_shell_message(self, msg=None, socket=None):
# If socket is None kernel subshells are not supported so use socket=shell_socket.
Expand Down Expand Up @@ -718,8 +718,7 @@ async def execute_request(self, socket, ident, parent):
cell_meta = parent.get("metadata", {})
cell_id = cell_meta.get("cellId")
except Exception:
self.log.error("Got bad msg: ")
self.log.error("%s", parent)
self.log.error("Got bad msg from parent: %s", parent)
return

stop_on_error = content.get("stop_on_error", True)
Expand Down Expand Up @@ -1101,8 +1100,7 @@ async def delete_subshell_request(self, socket, ident, parent):
content = parent["content"]
subshell_id = content["subshell_id"]
except Exception:
self.log.error("Got bad msg: ")
self.log.error("%s", parent)
self.log.error("Got bad msg from parent: %s", parent)
return

# This should only be called in the control thread if it exists.
Expand Down
8 changes: 4 additions & 4 deletions ipykernel/subshell_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def subshell_id_from_thread_id(self, thread_id) -> str | None:
for id, subshell in self._cache.items():
if subshell.thread.ident == thread_id:
return id
msg = f"Thread id '{thread_id} does not correspond to a subshell of this kernel"
msg = f"Thread id {thread_id!r} does not correspond to a subshell of this kernel"
raise RuntimeError(msg)

def _create_inproc_pair_socket(
Expand Down Expand Up @@ -235,11 +235,11 @@ async def _listen_for_subshell_reply(self, subshell_id: str | None) -> None:
msg = await shell_channel_socket.recv_multipart(copy=False)
with self._lock_shell_socket:
await self._shell_socket.send_multipart(msg)
except BaseException as e:
except BaseException:
if not self._is_subshell(subshell_id):
# Subshell no longer exists so exit gracefully
return
raise e
raise

async def _process_control_request(self, request, subshell_task) -> dict[str, t.Any]:
"""Process a control request message received on the control inproc
Expand All @@ -259,7 +259,7 @@ async def _process_control_request(self, request, subshell_task) -> dict[str, t.
elif type == "list":
reply["subshell_id"] = self.list_subshell()
else:
msg = f"Unrecognised message type {type}"
msg = f"Unrecognised message type {type!r}"
raise RuntimeError(msg)
except BaseException as err:
reply = {
Expand Down
9 changes: 5 additions & 4 deletions ipykernel/zmqshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import os
import sys
import threading
import warnings
from pathlib import Path
from threading import local

from IPython.core import page, payloadpage
from IPython.core.autocall import ZMQExitAutocall
Expand Down Expand Up @@ -69,7 +69,7 @@ def _flush_streams(self):
@default("_thread_local")
def _default_thread_local(self):
"""Initialize our thread local storage"""
return local()
return threading.local()

@property
def _hooks(self):
Expand Down Expand Up @@ -441,6 +441,9 @@ def autosave(self, arg_s):

@line_magic
def subshell(self, arg_s):
"""
List all current subshells
"""
from ipykernel.kernelapp import IPKernelApp

if not IPKernelApp.initialized():
Expand All @@ -454,8 +457,6 @@ def subshell(self, arg_s):
print("Kernel does not support subshells")
return

import threading

thread_id = threading.current_thread().ident
manager = kernel.shell_channel_thread.manager
try:
Expand Down

0 comments on commit d17c77f

Please sign in to comment.