Skip to content

Commit 96ec04d

Browse files
authored
Merge pull request #165 from takluyver/doc-stdin-generalise
Make stdin messaging docs not IPython specific
2 parents c5bcb82 + 81c705c commit 96ec04d

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

docs/messaging.rst

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,17 +1087,29 @@ Message type: ``clear_output``::
10871087
The selective clearing keys are ignored in v4 and the default behavior remains the same,
10881088
so v4 clear_output messages will be safely handled by a v4.1 frontend.
10891089

1090+
.. _stdin_messages:
10901091

10911092
Messages on the stdin ROUTER/DEALER sockets
10921093
===========================================
10931094

1094-
This is a socket where the request/reply pattern goes in the opposite direction:
1095-
from the kernel to a *single* frontend, and its purpose is to allow
1096-
``raw_input`` and similar operations that read from ``sys.stdin`` on the kernel
1097-
to be fulfilled by the client. The request should be made to the frontend that
1098-
made the execution request that prompted ``raw_input`` to be called. For now we
1099-
will keep these messages as simple as possible, since they only mean to convey
1100-
the ``raw_input(prompt)`` call.
1095+
With the stdin ROUTER/DEALER socket, the request/reply pattern goes in the
1096+
opposite direction of most kernel communication.
1097+
With the stdin socket, the kernel makes the request, and the single frontend
1098+
provides the response.
1099+
This pattern allows code to prompt the user for a line of input,
1100+
which would normally be read from stdin in a terminal.
1101+
1102+
Many programming languages provide a function which displays a prompt, blocks
1103+
until the user presses return, and returns the text they typed before pressing
1104+
return. In Python 3, this is the ``input()`` function; in R it is called
1105+
``readline()``. If the :ref:`execute_request <execute>` message has
1106+
``allow_stdin==True``, kernels may implement these functions so that they send
1107+
an ``input_request`` message and wait for a corresponding ``input_reply``. The
1108+
frontend is responsible for displaying the prompt and getting the user's input.
1109+
1110+
If ``allow_stdin`` is False, the kernel must not send ``stdin_request``. The
1111+
kernel may decide what to do instead, but it's most likely that calls to the
1112+
'prompt for input' function should fail immediately in this case.
11011113

11021114
Message type: ``input_request``::
11031115

@@ -1114,7 +1126,10 @@ Message type: ``input_reply``::
11141126
content = { 'value' : str }
11151127

11161128

1117-
When ``password`` is True, the frontend should not echo the input as it is entered.
1129+
When ``password`` is True, the frontend should not show the input as it is entered.
1130+
Different frontends may obscure it in different ways; e.g. showing each
1131+
character entered as the same neutral symbol, or not showing anything at all as
1132+
the user types.
11181133

11191134
.. versionchanged:: 5.0
11201135

@@ -1130,14 +1145,10 @@ When ``password`` is True, the frontend should not echo the input as it is enter
11301145

11311146
.. note::
11321147

1133-
We do not explicitly try to forward the raw ``sys.stdin`` object, because in
1134-
practice the kernel should behave like an interactive program. When a
1135-
program is opened on the console, the keyboard effectively takes over the
1136-
``stdin`` file descriptor, and it can't be used for raw reading anymore.
1137-
Since the IPython kernel effectively behaves like a console program (albeit
1138-
one whose "keyboard" is actually living in a separate process and
1139-
transported over the zmq connection), raw ``stdin`` isn't expected to be
1140-
available.
1148+
This pattern of requesting user input is quite different from how stdin works
1149+
at a lower level. The Jupyter protocol does not support everything code
1150+
running in a terminal can do with stdin, but we believe that this enables the
1151+
most common use cases.
11411152

11421153
.. _kernel_heartbeat:
11431154

0 commit comments

Comments
 (0)