Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _stdin_hook_default async #814

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio
import inspect
import sys
import time
import typing as t
Expand Down Expand Up @@ -232,7 +233,7 @@ async def _async_recv_reply(
continue
return reply

def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
async def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
"""Handle an input request"""
content = msg["content"]
if content.get("password", False):
Expand All @@ -251,7 +252,7 @@ def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:

# only send stdin reply if there *was not* another request
# or execution finished while we were reading.
if not (self.stdin_channel.msg_ready() or self.shell_channel.msg_ready()):
if not (await self.stdin_channel.msg_ready() or await self.shell_channel.msg_ready()):
self.input(raw_data)

def _output_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
Expand Down Expand Up @@ -469,7 +470,7 @@ async def _async_execute_interactive(
If not specified, output will be redisplayed.

stdin_hook: callable(msg)
Function to be called with stdin_request messages.
Function or awaitable to be called with stdin_request messages.
If not specified, input/getpass will be called.

Returns
Expand Down Expand Up @@ -536,7 +537,9 @@ async def _async_execute_interactive(
raise TimeoutError("Timeout waiting for output")
if stdin_socket in events:
req = await self.stdin_channel.get_msg(timeout=0)
stdin_hook(req)
res = stdin_hook(req)
if inspect.isawaitable(res):
await res
continue
if iopub_socket not in events:
continue
Expand Down