@@ -141,6 +141,7 @@ A message is defined by the following four-dictionary structure::
141
141
so implementers are strongly encouraged to include it.
142
142
It will be mandatory in 5.1.
143
143
144
+
144
145
.. _wire_protocol :
145
146
146
147
The Wire Protocol
@@ -256,8 +257,38 @@ All messages sent to or received by any IPython process should have this
256
257
extended structure.
257
258
258
259
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.
261
292
262
293
.. _execute :
263
294
@@ -391,26 +422,6 @@ When status is 'ok', the following extra fields are present::
391
422
392
423
``user_variables `` is removed, use user_expressions instead.
393
424
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.
414
425
415
426
Payloads (DEPRECATED)
416
427
~~~~~~~~~~~~~~~~~~~~~
@@ -889,8 +900,10 @@ Message type: ``shutdown_reply``::
889
900
process is unlikely to respond in any useful way to messages.
890
901
891
902
892
- Messages on the PUB/SUB socket
893
- ==============================
903
+ Messages on the IOPub (PUB/SUB) channel
904
+ =======================================
905
+
906
+
894
907
895
908
Streams (stdout, stderr, etc)
896
909
------------------------------
@@ -1053,9 +1066,28 @@ Message type: ``status``::
1053
1066
execution_state : ('busy', 'idle', 'starting')
1054
1067
}
1055
1068
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
+
1056
1088
.. versionchanged :: 5.0
1057
1089
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 ,
1059
1091
not just execution.
1060
1092
1061
1093
.. note ::
@@ -1090,8 +1122,8 @@ Message type: ``clear_output``::
1090
1122
1091
1123
.. _stdin_messages :
1092
1124
1093
- Messages on the stdin ROUTER/DEALER sockets
1094
- ===========================================
1125
+ Messages on the stdin ( ROUTER/DEALER) channel
1126
+ =============================================
1095
1127
1096
1128
With the stdin ROUTER/DEALER socket, the request/reply pattern goes in the
1097
1129
opposite direction of most kernel communication.
0 commit comments