2
2
# Copyright (c) Jupyter Development Team.
3
3
# Distributed under the terms of the Modified BSD License.
4
4
import asyncio
5
+ import inspect
5
6
import sys
6
7
import time
7
8
import typing as t
@@ -232,7 +233,7 @@ async def _async_recv_reply(
232
233
continue
233
234
return reply
234
235
235
- def _stdin_hook_default (self , msg : t .Dict [str , t .Any ]) -> None :
236
+ async def _stdin_hook_default (self , msg : t .Dict [str , t .Any ]) -> None :
236
237
"""Handle an input request"""
237
238
content = msg ["content" ]
238
239
if content .get ("password" , False ):
@@ -251,7 +252,7 @@ def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
251
252
252
253
# only send stdin reply if there *was not* another request
253
254
# or execution finished while we were reading.
254
- if not (self .stdin_channel .msg_ready () or self .shell_channel .msg_ready ()):
255
+ if not (await self .stdin_channel .msg_ready () or await self .shell_channel .msg_ready ()):
255
256
self .input (raw_data )
256
257
257
258
def _output_hook_default (self , msg : t .Dict [str , t .Any ]) -> None :
@@ -469,7 +470,7 @@ async def _async_execute_interactive(
469
470
If not specified, output will be redisplayed.
470
471
471
472
stdin_hook: callable(msg)
472
- Function to be called with stdin_request messages.
473
+ Function or awaitable to be called with stdin_request messages.
473
474
If not specified, input/getpass will be called.
474
475
475
476
Returns
@@ -536,7 +537,9 @@ async def _async_execute_interactive(
536
537
raise TimeoutError ("Timeout waiting for output" )
537
538
if stdin_socket in events :
538
539
req = await self .stdin_channel .get_msg (timeout = 0 )
539
- stdin_hook (req )
540
+ res = stdin_hook (req )
541
+ if inspect .isawaitable (res ):
542
+ await res
540
543
continue
541
544
if iopub_socket not in events :
542
545
continue
0 commit comments