Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 14, 2024
1 parent ee38f9e commit 04be394
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
16 changes: 12 additions & 4 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ async def start(self, *, task_status: TaskStatus = TASK_STATUS_IGNORED) -> None:
# Assign tasks to and start shell channel thread.
manager = self.shell_channel_thread.manager
self.shell_channel_thread.add_task(self.shell_channel_thread_main)
self.shell_channel_thread.add_task(manager.listen_from_control, self.shell_main, self.shell_channel_thread)
self.shell_channel_thread.add_task(
manager.listen_from_control, self.shell_main, self.shell_channel_thread
)
self.shell_channel_thread.add_task(manager.listen_from_subshells)
self.shell_channel_thread.start()
else:
Expand Down Expand Up @@ -1081,7 +1083,9 @@ async def create_subshell_request(self, socket, ident, parent) -> None:

# This should only be called in the control thread if it exists.
# Request is passed to shell channel thread to process.
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(self.control_thread.get_task_group())
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(
self.control_thread.get_task_group()
)
await other_socket.asend_json({"type": "create"})
reply = await other_socket.arecv_json()

Expand All @@ -1103,7 +1107,9 @@ async def delete_subshell_request(self, socket, ident, parent) -> None:

# This should only be called in the control thread if it exists.
# Request is passed to shell channel thread to process.
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(self.control_thread.get_task_group())
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(
self.control_thread.get_task_group()
)
await other_socket.asend_json({"type": "delete", "subshell_id": subshell_id})
reply = await other_socket.arecv_json()

Expand All @@ -1118,7 +1124,9 @@ async def list_subshell_request(self, socket, ident, parent) -> None:

# This should only be called in the control thread if it exists.
# Request is passed to shell channel thread to process.
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(self.control_thread.get_task_group())
other_socket = await self.shell_channel_thread.manager.get_control_other_socket(
self.control_thread.get_task_group()
)
await other_socket.asend_json({"type": "list"})
reply = await other_socket.arecv_json()

Expand Down
11 changes: 9 additions & 2 deletions ipykernel/subshell_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ class SubshellManager:
against multiple subshells attempting to send at the same time.
"""

def __init__(self, context: zmq.Context, shell_socket: zmq_anyio.Socket, get_task_group: Callable[[], TaskGroup]):
def __init__(
self,
context: zmq.Context,
shell_socket: zmq_anyio.Socket,
get_task_group: Callable[[], TaskGroup],
):
assert current_thread() == main_thread()

self._context: zmq.Context = context
Expand Down Expand Up @@ -229,7 +234,9 @@ def _is_subshell(self, subshell_id: str | None) -> bool:
with self._lock_cache:
return subshell_id in self._cache

async def _listen_for_subshell_reply(self, subshell_id: str | None, task_group: TaskGroup) -> None:
async def _listen_for_subshell_reply(
self, subshell_id: str | None, task_group: TaskGroup
) -> None:
"""Listen for reply messages on specified subshell inproc socket and
resend to the client via the shell_socket.
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
resource = None # type:ignore


@pytest.fixture
@pytest.fixture()
def anyio_backend():
return "asyncio"


pytestmark = pytest.mark.anyio


Expand Down

0 comments on commit 04be394

Please sign in to comment.