Skip to content

Commit ba062ad

Browse files
committed
Clarifications on some of the specification
- indicate that status=error doesn't require any fields from when status=ok to be defined - mention that status messages can be used to fence output (with async output caveat)
1 parent c5bcb82 commit ba062ad

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

@@ -390,26 +421,6 @@ When status is 'ok', the following extra fields are present::
390421

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

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

414425
Payloads (DEPRECATED)
415426
~~~~~~~~~~~~~~~~~~~~~
@@ -888,8 +899,10 @@ Message type: ``shutdown_reply``::
888899
process is unlikely to respond in any useful way to messages.
889900

890901

891-
Messages on the PUB/SUB socket
892-
==============================
902+
Messages on the IOPub (PUB/SUB) channel
903+
=======================================
904+
905+
893906

894907
Streams (stdout, stderr, etc)
895908
------------------------------
@@ -1052,9 +1065,28 @@ Message type: ``status``::
10521065
execution_state : ('busy', 'idle', 'starting')
10531066
}
10541067

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

1057-
Busy and idle messages should be sent before/after handling every message,
1089+
Busy and idle messages should be sent before/after handling every request,
10581090
not just execution.
10591091

10601092
.. note::
@@ -1088,8 +1120,8 @@ Message type: ``clear_output``::
10881120
so v4 clear_output messages will be safely handled by a v4.1 frontend.
10891121

10901122

1091-
Messages on the stdin ROUTER/DEALER sockets
1092-
===========================================
1123+
Messages on the stdin (ROUTER/DEALER) channel
1124+
=============================================
10931125

10941126
This is a socket where the request/reply pattern goes in the opposite direction:
10951127
from the kernel to a *single* frontend, and its purpose is to allow

0 commit comments

Comments
 (0)