Skip to content

Commit fb0da68

Browse files
authored
Merge pull request #164 from minrk/messaging-specificity
Clarifications on some of the specification
2 parents 421a2f6 + ba062ad commit fb0da68

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

docs/messaging.rst

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ A message is defined by the following four-dictionary structure::
141141
so implementers are strongly encouraged to include it.
142142
It will be mandatory in 5.1.
143143

144+
144145
.. _wire_protocol:
145146

146147
The Wire Protocol
@@ -256,8 +257,38 @@ All messages sent to or received by any IPython process should have this
256257
extended structure.
257258

258259

259-
Messages on the shell ROUTER/DEALER sockets
260-
===========================================
260+
Messages on the shell (ROUTER/DEALER) channel
261+
=============================================
262+
263+
.. _request_reply:
264+
265+
Request-Reply
266+
-------------
267+
268+
In general, the ROUTER/DEALER sockets follow a request-reply pattern:
269+
270+
The client sends an ``<action>_request`` message (such as ``execute_request``) on its shell (DEALER) socket.
271+
The kernel receives that request and immediately publishes a ``status: busy`` message on IOPub.
272+
The kernel then processes the request and sends the appropriate ``<action>_reply`` message, such as ``execute_reply``.
273+
After processing the request and publishing associated IOPub messages, if any,
274+
the kernel publishes a ``status: idle`` message.
275+
This idle status message indicates that IOPub messages associated with a given request have all been received.
276+
277+
All reply messages have a ``'status'`` field, which will have one of the following values:
278+
279+
- ``status='ok'``: The request was processed successfully, and the remaining content of the reply is specified in the appropriate section below.
280+
- ``status='error'``: The request failed due to an error.
281+
When status is 'error', the usual content of a successful reply should be omitted,
282+
instead the following fields should be present::
283+
284+
{
285+
'status' : 'error',
286+
'ename' : str, # Exception name, as a string
287+
'evalue' : str, # Exception value, as a string
288+
'traceback' : list(str), # traceback frames as strings
289+
}
290+
291+
- ``status='abort'``: the task has been aborted. In this case, no additional fields should be present.
261292

262293
.. _execute:
263294

@@ -391,26 +422,6 @@ When status is 'ok', the following extra fields are present::
391422

392423
``user_variables`` is removed, use user_expressions instead.
393424

394-
When status is 'error', the following extra fields are present::
395-
396-
{
397-
'ename' : str, # Exception name, as a string
398-
'evalue' : str, # Exception value, as a string
399-
400-
# The traceback will contain a list of frames, represented each as a
401-
# string. For now we'll stick to the existing design of ultraTB, which
402-
# controls exception level of detail statefully. But eventually we'll
403-
# want to grow into a model where more information is collected and
404-
# packed into the traceback object, with clients deciding how little or
405-
# how much of it to unpack. But for now, let's start with a simple list
406-
# of strings, since that requires only minimal changes to ultratb as
407-
# written.
408-
'traceback' : list,
409-
}
410-
411-
412-
When status is 'abort', there are for now no additional data fields. This
413-
happens when the kernel was interrupted by a signal.
414425

415426
Payloads (DEPRECATED)
416427
~~~~~~~~~~~~~~~~~~~~~
@@ -889,8 +900,10 @@ Message type: ``shutdown_reply``::
889900
process is unlikely to respond in any useful way to messages.
890901

891902

892-
Messages on the PUB/SUB socket
893-
==============================
903+
Messages on the IOPub (PUB/SUB) channel
904+
=======================================
905+
906+
894907

895908
Streams (stdout, stderr, etc)
896909
------------------------------
@@ -1053,9 +1066,28 @@ Message type: ``status``::
10531066
execution_state : ('busy', 'idle', 'starting')
10541067
}
10551068

1069+
When a kernel receives a request and begins processing it,
1070+
the kernel shall immediately publish a status message with ``execution_state: 'busy'``.
1071+
When that kernel has completed processing the request
1072+
and has finished publishing associated IOPub messages, if any,
1073+
it shall publish a status message with ``execution_state: 'idle'``.
1074+
Thus, the outputs associated with a given execution shall generally arrive
1075+
between the busy and idle status messages associated with a given request.
1076+
1077+
.. note::
1078+
1079+
**A caveat for asynchronous output**
1080+
1081+
Asynchronous output (e.g. from background threads) may be produced after the kernel
1082+
has sent the idle status message that signals the completion of the request.
1083+
The handling of these out-of-order output messages is currently undefined in this specification,
1084+
but the Jupyter Notebook continues to handle IOPub messages associated with a given request
1085+
after the idle message has arrived,
1086+
as long as the output area corresponding to that request is still active.
1087+
10561088
.. versionchanged:: 5.0
10571089

1058-
Busy and idle messages should be sent before/after handling every message,
1090+
Busy and idle messages should be sent before/after handling every request,
10591091
not just execution.
10601092

10611093
.. note::
@@ -1090,8 +1122,8 @@ Message type: ``clear_output``::
10901122

10911123
.. _stdin_messages:
10921124

1093-
Messages on the stdin ROUTER/DEALER sockets
1094-
===========================================
1125+
Messages on the stdin (ROUTER/DEALER) channel
1126+
=============================================
10951127

10961128
With the stdin ROUTER/DEALER socket, the request/reply pattern goes in the
10971129
opposite direction of most kernel communication.

0 commit comments

Comments
 (0)