@@ -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
@@ -390,26 +421,6 @@ When status is 'ok', the following extra fields are present::
390
421
391
422
``user_variables `` is removed, use user_expressions instead.
392
423
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.
413
424
414
425
Payloads (DEPRECATED)
415
426
~~~~~~~~~~~~~~~~~~~~~
@@ -888,8 +899,10 @@ Message type: ``shutdown_reply``::
888
899
process is unlikely to respond in any useful way to messages.
889
900
890
901
891
- Messages on the PUB/SUB socket
892
- ==============================
902
+ Messages on the IOPub (PUB/SUB) channel
903
+ =======================================
904
+
905
+
893
906
894
907
Streams (stdout, stderr, etc)
895
908
------------------------------
@@ -1052,9 +1065,28 @@ Message type: ``status``::
1052
1065
execution_state : ('busy', 'idle', 'starting')
1053
1066
}
1054
1067
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
+
1055
1087
.. versionchanged :: 5.0
1056
1088
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 ,
1058
1090
not just execution.
1059
1091
1060
1092
.. note ::
@@ -1088,8 +1120,8 @@ Message type: ``clear_output``::
1088
1120
so v4 clear_output messages will be safely handled by a v4.1 frontend.
1089
1121
1090
1122
1091
- Messages on the stdin ROUTER/DEALER sockets
1092
- ===========================================
1123
+ Messages on the stdin ( ROUTER/DEALER) channel
1124
+ =============================================
1093
1125
1094
1126
This is a socket where the request/reply pattern goes in the opposite direction:
1095
1127
from the kernel to a *single * frontend, and its purpose is to allow
0 commit comments