Skip to content

Commit

Permalink
Merge pull request #814 from davidbrochart/async_stdin_hook
Browse files Browse the repository at this point in the history
Make _stdin_hook_default async
  • Loading branch information
davidbrochart authored Jul 8, 2022
2 parents 5b2aa2b + 238761a commit 4bb7ac5
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 4bb7ac5

Please sign in to comment.