##// END OF EJS Templates
Merge pull request #8408 from minrk/inspect-found...
Thomas Kluyver -
r21331:a7d74cfd merge
parent child Browse files
Show More
@@ -1,1216 +1,1219
1 .. _messaging:
1 .. _messaging:
2
2
3 ======================
3 ======================
4 Messaging in IPython
4 Messaging in IPython
5 ======================
5 ======================
6
6
7
7
8 Versioning
8 Versioning
9 ==========
9 ==========
10
10
11 The IPython message specification is versioned independently of IPython.
11 The IPython message specification is versioned independently of IPython.
12 The current version of the specification is 5.0.
12 The current version of the specification is 5.0.
13
13
14
14
15 Introduction
15 Introduction
16 ============
16 ============
17
17
18 This document explains the basic communications design and messaging
18 This document explains the basic communications design and messaging
19 specification for how the various IPython objects interact over a network
19 specification for how the various IPython objects interact over a network
20 transport. The current implementation uses the ZeroMQ_ library for messaging
20 transport. The current implementation uses the ZeroMQ_ library for messaging
21 within and between hosts.
21 within and between hosts.
22
22
23 .. Note::
23 .. Note::
24
24
25 This document should be considered the authoritative description of the
25 This document should be considered the authoritative description of the
26 IPython messaging protocol, and all developers are strongly encouraged to
26 IPython messaging protocol, and all developers are strongly encouraged to
27 keep it updated as the implementation evolves, so that we have a single
27 keep it updated as the implementation evolves, so that we have a single
28 common reference for all protocol details.
28 common reference for all protocol details.
29
29
30 The basic design is explained in the following diagram:
30 The basic design is explained in the following diagram:
31
31
32 .. image:: figs/frontend-kernel.png
32 .. image:: figs/frontend-kernel.png
33 :width: 450px
33 :width: 450px
34 :alt: IPython kernel/frontend messaging architecture.
34 :alt: IPython kernel/frontend messaging architecture.
35 :align: center
35 :align: center
36 :target: ../_images/frontend-kernel.png
36 :target: ../_images/frontend-kernel.png
37
37
38 A single kernel can be simultaneously connected to one or more frontends. The
38 A single kernel can be simultaneously connected to one or more frontends. The
39 kernel has three sockets that serve the following functions:
39 kernel has three sockets that serve the following functions:
40
40
41 1. Shell: this single ROUTER socket allows multiple incoming connections from
41 1. Shell: this single ROUTER socket allows multiple incoming connections from
42 frontends, and this is the socket where requests for code execution, object
42 frontends, and this is the socket where requests for code execution, object
43 information, prompts, etc. are made to the kernel by any frontend. The
43 information, prompts, etc. are made to the kernel by any frontend. The
44 communication on this socket is a sequence of request/reply actions from
44 communication on this socket is a sequence of request/reply actions from
45 each frontend and the kernel.
45 each frontend and the kernel.
46
46
47 2. IOPub: this socket is the 'broadcast channel' where the kernel publishes all
47 2. IOPub: this socket is the 'broadcast channel' where the kernel publishes all
48 side effects (stdout, stderr, etc.) as well as the requests coming from any
48 side effects (stdout, stderr, etc.) as well as the requests coming from any
49 client over the shell socket and its own requests on the stdin socket. There
49 client over the shell socket and its own requests on the stdin socket. There
50 are a number of actions in Python which generate side effects: :func:`print`
50 are a number of actions in Python which generate side effects: :func:`print`
51 writes to ``sys.stdout``, errors generate tracebacks, etc. Additionally, in
51 writes to ``sys.stdout``, errors generate tracebacks, etc. Additionally, in
52 a multi-client scenario, we want all frontends to be able to know what each
52 a multi-client scenario, we want all frontends to be able to know what each
53 other has sent to the kernel (this can be useful in collaborative scenarios,
53 other has sent to the kernel (this can be useful in collaborative scenarios,
54 for example). This socket allows both side effects and the information
54 for example). This socket allows both side effects and the information
55 about communications taking place with one client over the shell channel
55 about communications taking place with one client over the shell channel
56 to be made available to all clients in a uniform manner.
56 to be made available to all clients in a uniform manner.
57
57
58 3. stdin: this ROUTER socket is connected to all frontends, and it allows
58 3. stdin: this ROUTER socket is connected to all frontends, and it allows
59 the kernel to request input from the active frontend when :func:`raw_input` is called.
59 the kernel to request input from the active frontend when :func:`raw_input` is called.
60 The frontend that executed the code has a DEALER socket that acts as a 'virtual keyboard'
60 The frontend that executed the code has a DEALER socket that acts as a 'virtual keyboard'
61 for the kernel while this communication is happening (illustrated in the
61 for the kernel while this communication is happening (illustrated in the
62 figure by the black outline around the central keyboard). In practice,
62 figure by the black outline around the central keyboard). In practice,
63 frontends may display such kernel requests using a special input widget or
63 frontends may display such kernel requests using a special input widget or
64 otherwise indicating that the user is to type input for the kernel instead
64 otherwise indicating that the user is to type input for the kernel instead
65 of normal commands in the frontend.
65 of normal commands in the frontend.
66
66
67 All messages are tagged with enough information (details below) for clients
67 All messages are tagged with enough information (details below) for clients
68 to know which messages come from their own interaction with the kernel and
68 to know which messages come from their own interaction with the kernel and
69 which ones are from other clients, so they can display each type
69 which ones are from other clients, so they can display each type
70 appropriately.
70 appropriately.
71
71
72 4. Control: This channel is identical to Shell, but operates on a separate socket,
72 4. Control: This channel is identical to Shell, but operates on a separate socket,
73 to allow important messages to avoid queueing behind execution requests (e.g. shutdown or abort).
73 to allow important messages to avoid queueing behind execution requests (e.g. shutdown or abort).
74
74
75 The actual format of the messages allowed on each of these channels is
75 The actual format of the messages allowed on each of these channels is
76 specified below. Messages are dicts of dicts with string keys and values that
76 specified below. Messages are dicts of dicts with string keys and values that
77 are reasonably representable in JSON. Our current implementation uses JSON
77 are reasonably representable in JSON. Our current implementation uses JSON
78 explicitly as its message format, but this shouldn't be considered a permanent
78 explicitly as its message format, but this shouldn't be considered a permanent
79 feature. As we've discovered that JSON has non-trivial performance issues due
79 feature. As we've discovered that JSON has non-trivial performance issues due
80 to excessive copying, we may in the future move to a pure pickle-based raw
80 to excessive copying, we may in the future move to a pure pickle-based raw
81 message format. However, it should be possible to easily convert from the raw
81 message format. However, it should be possible to easily convert from the raw
82 objects to JSON, since we may have non-python clients (e.g. a web frontend).
82 objects to JSON, since we may have non-python clients (e.g. a web frontend).
83 As long as it's easy to make a JSON version of the objects that is a faithful
83 As long as it's easy to make a JSON version of the objects that is a faithful
84 representation of all the data, we can communicate with such clients.
84 representation of all the data, we can communicate with such clients.
85
85
86 .. Note::
86 .. Note::
87
87
88 Not all of these have yet been fully fleshed out, but the key ones are, see
88 Not all of these have yet been fully fleshed out, but the key ones are, see
89 kernel and frontend files for actual implementation details.
89 kernel and frontend files for actual implementation details.
90
90
91 General Message Format
91 General Message Format
92 ======================
92 ======================
93
93
94 A message is defined by the following four-dictionary structure::
94 A message is defined by the following four-dictionary structure::
95
95
96 {
96 {
97 # The message header contains a pair of unique identifiers for the
97 # The message header contains a pair of unique identifiers for the
98 # originating session and the actual message id, in addition to the
98 # originating session and the actual message id, in addition to the
99 # username for the process that generated the message. This is useful in
99 # username for the process that generated the message. This is useful in
100 # collaborative settings where multiple users may be interacting with the
100 # collaborative settings where multiple users may be interacting with the
101 # same kernel simultaneously, so that frontends can label the various
101 # same kernel simultaneously, so that frontends can label the various
102 # messages in a meaningful way.
102 # messages in a meaningful way.
103 'header' : {
103 'header' : {
104 'msg_id' : uuid,
104 'msg_id' : uuid,
105 'username' : str,
105 'username' : str,
106 'session' : uuid,
106 'session' : uuid,
107 # All recognized message type strings are listed below.
107 # All recognized message type strings are listed below.
108 'msg_type' : str,
108 'msg_type' : str,
109 # the message protocol version
109 # the message protocol version
110 'version' : '5.0',
110 'version' : '5.0',
111 },
111 },
112
112
113 # In a chain of messages, the header from the parent is copied so that
113 # In a chain of messages, the header from the parent is copied so that
114 # clients can track where messages come from.
114 # clients can track where messages come from.
115 'parent_header' : dict,
115 'parent_header' : dict,
116
116
117 # Any metadata associated with the message.
117 # Any metadata associated with the message.
118 'metadata' : dict,
118 'metadata' : dict,
119
119
120 # The actual content of the message must be a dict, whose structure
120 # The actual content of the message must be a dict, whose structure
121 # depends on the message type.
121 # depends on the message type.
122 'content' : dict,
122 'content' : dict,
123 }
123 }
124
124
125 .. versionchanged:: 5.0
125 .. versionchanged:: 5.0
126
126
127 ``version`` key added to the header.
127 ``version`` key added to the header.
128
128
129 .. _wire_protocol:
129 .. _wire_protocol:
130
130
131 The Wire Protocol
131 The Wire Protocol
132 =================
132 =================
133
133
134
134
135 This message format exists at a high level,
135 This message format exists at a high level,
136 but does not describe the actual *implementation* at the wire level in zeromq.
136 but does not describe the actual *implementation* at the wire level in zeromq.
137 The canonical implementation of the message spec is our :class:`~IPython.kernel.zmq.session.Session` class.
137 The canonical implementation of the message spec is our :class:`~IPython.kernel.zmq.session.Session` class.
138
138
139 .. note::
139 .. note::
140
140
141 This section should only be relevant to non-Python consumers of the protocol.
141 This section should only be relevant to non-Python consumers of the protocol.
142 Python consumers should simply import and use IPython's own implementation of the wire protocol
142 Python consumers should simply import and use IPython's own implementation of the wire protocol
143 in the :class:`IPython.kernel.zmq.session.Session` object.
143 in the :class:`IPython.kernel.zmq.session.Session` object.
144
144
145 Every message is serialized to a sequence of at least six blobs of bytes:
145 Every message is serialized to a sequence of at least six blobs of bytes:
146
146
147 .. sourcecode:: python
147 .. sourcecode:: python
148
148
149 [
149 [
150 b'u-u-i-d', # zmq identity(ies)
150 b'u-u-i-d', # zmq identity(ies)
151 b'<IDS|MSG>', # delimiter
151 b'<IDS|MSG>', # delimiter
152 b'baddad42', # HMAC signature
152 b'baddad42', # HMAC signature
153 b'{header}', # serialized header dict
153 b'{header}', # serialized header dict
154 b'{parent_header}', # serialized parent header dict
154 b'{parent_header}', # serialized parent header dict
155 b'{metadata}', # serialized metadata dict
155 b'{metadata}', # serialized metadata dict
156 b'{content}', # serialized content dict
156 b'{content}', # serialized content dict
157 b'blob', # extra raw data buffer(s)
157 b'blob', # extra raw data buffer(s)
158 ...
158 ...
159 ]
159 ]
160
160
161 The front of the message is the ZeroMQ routing prefix,
161 The front of the message is the ZeroMQ routing prefix,
162 which can be zero or more socket identities.
162 which can be zero or more socket identities.
163 This is every piece of the message prior to the delimiter key ``<IDS|MSG>``.
163 This is every piece of the message prior to the delimiter key ``<IDS|MSG>``.
164 In the case of IOPub, there should be just one prefix component,
164 In the case of IOPub, there should be just one prefix component,
165 which is the topic for IOPub subscribers, e.g. ``execute_result``, ``display_data``.
165 which is the topic for IOPub subscribers, e.g. ``execute_result``, ``display_data``.
166
166
167 .. note::
167 .. note::
168
168
169 In most cases, the IOPub topics are irrelevant and completely ignored,
169 In most cases, the IOPub topics are irrelevant and completely ignored,
170 because frontends just subscribe to all topics.
170 because frontends just subscribe to all topics.
171 The convention used in the IPython kernel is to use the msg_type as the topic,
171 The convention used in the IPython kernel is to use the msg_type as the topic,
172 and possibly extra information about the message, e.g. ``execute_result`` or ``stream.stdout``
172 and possibly extra information about the message, e.g. ``execute_result`` or ``stream.stdout``
173
173
174 After the delimiter is the `HMAC`_ signature of the message, used for authentication.
174 After the delimiter is the `HMAC`_ signature of the message, used for authentication.
175 If authentication is disabled, this should be an empty string.
175 If authentication is disabled, this should be an empty string.
176 By default, the hashing function used for computing these signatures is sha256.
176 By default, the hashing function used for computing these signatures is sha256.
177
177
178 .. _HMAC: http://en.wikipedia.org/wiki/HMAC
178 .. _HMAC: http://en.wikipedia.org/wiki/HMAC
179
179
180 .. note::
180 .. note::
181
181
182 To disable authentication and signature checking,
182 To disable authentication and signature checking,
183 set the `key` field of a connection file to an empty string.
183 set the `key` field of a connection file to an empty string.
184
184
185 The signature is the HMAC hex digest of the concatenation of:
185 The signature is the HMAC hex digest of the concatenation of:
186
186
187 - A shared key (typically the ``key`` field of a connection file)
187 - A shared key (typically the ``key`` field of a connection file)
188 - The serialized header dict
188 - The serialized header dict
189 - The serialized parent header dict
189 - The serialized parent header dict
190 - The serialized metadata dict
190 - The serialized metadata dict
191 - The serialized content dict
191 - The serialized content dict
192
192
193 In Python, this is implemented via:
193 In Python, this is implemented via:
194
194
195 .. sourcecode:: python
195 .. sourcecode:: python
196
196
197 # once:
197 # once:
198 digester = HMAC(key, digestmod=hashlib.sha256)
198 digester = HMAC(key, digestmod=hashlib.sha256)
199
199
200 # for each message
200 # for each message
201 d = digester.copy()
201 d = digester.copy()
202 for serialized_dict in (header, parent, metadata, content):
202 for serialized_dict in (header, parent, metadata, content):
203 d.update(serialized_dict)
203 d.update(serialized_dict)
204 signature = d.hexdigest()
204 signature = d.hexdigest()
205
205
206 After the signature is the actual message, always in four frames of bytes.
206 After the signature is the actual message, always in four frames of bytes.
207 The four dictionaries that compose a message are serialized separately,
207 The four dictionaries that compose a message are serialized separately,
208 in the order of header, parent header, metadata, and content.
208 in the order of header, parent header, metadata, and content.
209 These can be serialized by any function that turns a dict into bytes.
209 These can be serialized by any function that turns a dict into bytes.
210 The default and most common serialization is JSON, but msgpack and pickle
210 The default and most common serialization is JSON, but msgpack and pickle
211 are common alternatives.
211 are common alternatives.
212
212
213 After the serialized dicts are zero to many raw data buffers,
213 After the serialized dicts are zero to many raw data buffers,
214 which can be used by message types that support binary data (mainly apply and data_pub).
214 which can be used by message types that support binary data (mainly apply and data_pub).
215
215
216
216
217 Python functional API
217 Python functional API
218 =====================
218 =====================
219
219
220 As messages are dicts, they map naturally to a ``func(**kw)`` call form. We
220 As messages are dicts, they map naturally to a ``func(**kw)`` call form. We
221 should develop, at a few key points, functional forms of all the requests that
221 should develop, at a few key points, functional forms of all the requests that
222 take arguments in this manner and automatically construct the necessary dict
222 take arguments in this manner and automatically construct the necessary dict
223 for sending.
223 for sending.
224
224
225 In addition, the Python implementation of the message specification extends
225 In addition, the Python implementation of the message specification extends
226 messages upon deserialization to the following form for convenience::
226 messages upon deserialization to the following form for convenience::
227
227
228 {
228 {
229 'header' : dict,
229 'header' : dict,
230 # The msg's unique identifier and type are always stored in the header,
230 # The msg's unique identifier and type are always stored in the header,
231 # but the Python implementation copies them to the top level.
231 # but the Python implementation copies them to the top level.
232 'msg_id' : uuid,
232 'msg_id' : uuid,
233 'msg_type' : str,
233 'msg_type' : str,
234 'parent_header' : dict,
234 'parent_header' : dict,
235 'content' : dict,
235 'content' : dict,
236 'metadata' : dict,
236 'metadata' : dict,
237 }
237 }
238
238
239 All messages sent to or received by any IPython process should have this
239 All messages sent to or received by any IPython process should have this
240 extended structure.
240 extended structure.
241
241
242
242
243 Messages on the shell ROUTER/DEALER sockets
243 Messages on the shell ROUTER/DEALER sockets
244 ===========================================
244 ===========================================
245
245
246 .. _execute:
246 .. _execute:
247
247
248 Execute
248 Execute
249 -------
249 -------
250
250
251 This message type is used by frontends to ask the kernel to execute code on
251 This message type is used by frontends to ask the kernel to execute code on
252 behalf of the user, in a namespace reserved to the user's variables (and thus
252 behalf of the user, in a namespace reserved to the user's variables (and thus
253 separate from the kernel's own internal code and variables).
253 separate from the kernel's own internal code and variables).
254
254
255 Message type: ``execute_request``::
255 Message type: ``execute_request``::
256
256
257 content = {
257 content = {
258 # Source code to be executed by the kernel, one or more lines.
258 # Source code to be executed by the kernel, one or more lines.
259 'code' : str,
259 'code' : str,
260
260
261 # A boolean flag which, if True, signals the kernel to execute
261 # A boolean flag which, if True, signals the kernel to execute
262 # this code as quietly as possible.
262 # this code as quietly as possible.
263 # silent=True forces store_history to be False,
263 # silent=True forces store_history to be False,
264 # and will *not*:
264 # and will *not*:
265 # - broadcast output on the IOPUB channel
265 # - broadcast output on the IOPUB channel
266 # - have an execute_result
266 # - have an execute_result
267 # The default is False.
267 # The default is False.
268 'silent' : bool,
268 'silent' : bool,
269
269
270 # A boolean flag which, if True, signals the kernel to populate history
270 # A boolean flag which, if True, signals the kernel to populate history
271 # The default is True if silent is False. If silent is True, store_history
271 # The default is True if silent is False. If silent is True, store_history
272 # is forced to be False.
272 # is forced to be False.
273 'store_history' : bool,
273 'store_history' : bool,
274
274
275 # A dict mapping names to expressions to be evaluated in the
275 # A dict mapping names to expressions to be evaluated in the
276 # user's dict. The rich display-data representation of each will be evaluated after execution.
276 # user's dict. The rich display-data representation of each will be evaluated after execution.
277 # See the display_data content for the structure of the representation data.
277 # See the display_data content for the structure of the representation data.
278 'user_expressions' : dict,
278 'user_expressions' : dict,
279
279
280 # Some frontends do not support stdin requests.
280 # Some frontends do not support stdin requests.
281 # If raw_input is called from code executed from such a frontend,
281 # If raw_input is called from code executed from such a frontend,
282 # a StdinNotImplementedError will be raised.
282 # a StdinNotImplementedError will be raised.
283 'allow_stdin' : True,
283 'allow_stdin' : True,
284
284
285 # A boolean flag, which, if True, does not abort the execution queue, if an exception is encountered.
285 # A boolean flag, which, if True, does not abort the execution queue, if an exception is encountered.
286 # This allows the queued execution of multiple execute_requests, even if they generate exceptions.
286 # This allows the queued execution of multiple execute_requests, even if they generate exceptions.
287 'stop_on_error' : False,
287 'stop_on_error' : False,
288 }
288 }
289
289
290 .. versionchanged:: 5.0
290 .. versionchanged:: 5.0
291
291
292 ``user_variables`` removed, because it is redundant with user_expressions.
292 ``user_variables`` removed, because it is redundant with user_expressions.
293
293
294 The ``code`` field contains a single string (possibly multiline) to be executed.
294 The ``code`` field contains a single string (possibly multiline) to be executed.
295
295
296 The ``user_expressions`` field deserves a detailed explanation. In the past, IPython had
296 The ``user_expressions`` field deserves a detailed explanation. In the past, IPython had
297 the notion of a prompt string that allowed arbitrary code to be evaluated, and
297 the notion of a prompt string that allowed arbitrary code to be evaluated, and
298 this was put to good use by many in creating prompts that displayed system
298 this was put to good use by many in creating prompts that displayed system
299 status, path information, and even more esoteric uses like remote instrument
299 status, path information, and even more esoteric uses like remote instrument
300 status acquired over the network. But now that IPython has a clean separation
300 status acquired over the network. But now that IPython has a clean separation
301 between the kernel and the clients, the kernel has no prompt knowledge; prompts
301 between the kernel and the clients, the kernel has no prompt knowledge; prompts
302 are a frontend feature, and it should be even possible for different
302 are a frontend feature, and it should be even possible for different
303 frontends to display different prompts while interacting with the same kernel.
303 frontends to display different prompts while interacting with the same kernel.
304 ``user_expressions`` can be used to retrieve this information.
304 ``user_expressions`` can be used to retrieve this information.
305
305
306 Any error in evaluating any expression in ``user_expressions`` will result in
306 Any error in evaluating any expression in ``user_expressions`` will result in
307 only that key containing a standard error message, of the form::
307 only that key containing a standard error message, of the form::
308
308
309 {
309 {
310 'status' : 'error',
310 'status' : 'error',
311 'ename' : 'NameError',
311 'ename' : 'NameError',
312 'evalue' : 'foo',
312 'evalue' : 'foo',
313 'traceback' : ...
313 'traceback' : ...
314 }
314 }
315
315
316 .. Note::
316 .. Note::
317
317
318 In order to obtain the current execution counter for the purposes of
318 In order to obtain the current execution counter for the purposes of
319 displaying input prompts, frontends may make an execution request with an
319 displaying input prompts, frontends may make an execution request with an
320 empty code string and ``silent=True``.
320 empty code string and ``silent=True``.
321
321
322 Upon completion of the execution request, the kernel *always* sends a reply,
322 Upon completion of the execution request, the kernel *always* sends a reply,
323 with a status code indicating what happened and additional data depending on
323 with a status code indicating what happened and additional data depending on
324 the outcome. See :ref:`below <execution_results>` for the possible return
324 the outcome. See :ref:`below <execution_results>` for the possible return
325 codes and associated data.
325 codes and associated data.
326
326
327 .. seealso::
327 .. seealso::
328
328
329 :ref:`execution_semantics`
329 :ref:`execution_semantics`
330
330
331 .. _execution_counter:
331 .. _execution_counter:
332
332
333 Execution counter (prompt number)
333 Execution counter (prompt number)
334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335
335
336 The kernel should have a single, monotonically increasing counter of all execution
336 The kernel should have a single, monotonically increasing counter of all execution
337 requests that are made with ``store_history=True``. This counter is used to populate
337 requests that are made with ``store_history=True``. This counter is used to populate
338 the ``In[n]`` and ``Out[n]`` prompts. The value of this counter will be returned as the
338 the ``In[n]`` and ``Out[n]`` prompts. The value of this counter will be returned as the
339 ``execution_count`` field of all ``execute_reply`` and ``execute_input`` messages.
339 ``execution_count`` field of all ``execute_reply`` and ``execute_input`` messages.
340
340
341 .. _execution_results:
341 .. _execution_results:
342
342
343 Execution results
343 Execution results
344 ~~~~~~~~~~~~~~~~~
344 ~~~~~~~~~~~~~~~~~
345
345
346 Message type: ``execute_reply``::
346 Message type: ``execute_reply``::
347
347
348 content = {
348 content = {
349 # One of: 'ok' OR 'error' OR 'abort'
349 # One of: 'ok' OR 'error' OR 'abort'
350 'status' : str,
350 'status' : str,
351
351
352 # The global kernel counter that increases by one with each request that
352 # The global kernel counter that increases by one with each request that
353 # stores history. This will typically be used by clients to display
353 # stores history. This will typically be used by clients to display
354 # prompt numbers to the user. If the request did not store history, this will
354 # prompt numbers to the user. If the request did not store history, this will
355 # be the current value of the counter in the kernel.
355 # be the current value of the counter in the kernel.
356 'execution_count' : int,
356 'execution_count' : int,
357 }
357 }
358
358
359 When status is 'ok', the following extra fields are present::
359 When status is 'ok', the following extra fields are present::
360
360
361 {
361 {
362 # 'payload' will be a list of payload dicts, and is optional.
362 # 'payload' will be a list of payload dicts, and is optional.
363 # payloads are considered deprecated.
363 # payloads are considered deprecated.
364 # The only requirement of each payload dict is that it have a 'source' key,
364 # The only requirement of each payload dict is that it have a 'source' key,
365 # which is a string classifying the payload (e.g. 'page').
365 # which is a string classifying the payload (e.g. 'page').
366
366
367 'payload' : list(dict),
367 'payload' : list(dict),
368
368
369 # Results for the user_expressions.
369 # Results for the user_expressions.
370 'user_expressions' : dict,
370 'user_expressions' : dict,
371 }
371 }
372
372
373 .. versionchanged:: 5.0
373 .. versionchanged:: 5.0
374
374
375 ``user_variables`` is removed, use user_expressions instead.
375 ``user_variables`` is removed, use user_expressions instead.
376
376
377 When status is 'error', the following extra fields are present::
377 When status is 'error', the following extra fields are present::
378
378
379 {
379 {
380 'ename' : str, # Exception name, as a string
380 'ename' : str, # Exception name, as a string
381 'evalue' : str, # Exception value, as a string
381 'evalue' : str, # Exception value, as a string
382
382
383 # The traceback will contain a list of frames, represented each as a
383 # The traceback will contain a list of frames, represented each as a
384 # string. For now we'll stick to the existing design of ultraTB, which
384 # string. For now we'll stick to the existing design of ultraTB, which
385 # controls exception level of detail statefully. But eventually we'll
385 # controls exception level of detail statefully. But eventually we'll
386 # want to grow into a model where more information is collected and
386 # want to grow into a model where more information is collected and
387 # packed into the traceback object, with clients deciding how little or
387 # packed into the traceback object, with clients deciding how little or
388 # how much of it to unpack. But for now, let's start with a simple list
388 # how much of it to unpack. But for now, let's start with a simple list
389 # of strings, since that requires only minimal changes to ultratb as
389 # of strings, since that requires only minimal changes to ultratb as
390 # written.
390 # written.
391 'traceback' : list,
391 'traceback' : list,
392 }
392 }
393
393
394
394
395 When status is 'abort', there are for now no additional data fields. This
395 When status is 'abort', there are for now no additional data fields. This
396 happens when the kernel was interrupted by a signal.
396 happens when the kernel was interrupted by a signal.
397
397
398 Payloads
398 Payloads
399 ********
399 ********
400
400
401 .. admonition:: Execution payloads
401 .. admonition:: Execution payloads
402
402
403 Payloads are considered deprecated, though their replacement is not yet implemented.
403 Payloads are considered deprecated, though their replacement is not yet implemented.
404
404
405 Payloads are a way to trigger frontend actions from the kernel. Current payloads:
405 Payloads are a way to trigger frontend actions from the kernel. Current payloads:
406
406
407 **page**: display data in a pager.
407 **page**: display data in a pager.
408
408
409 Pager output is used for introspection, or other displayed information that's not considered output.
409 Pager output is used for introspection, or other displayed information that's not considered output.
410 Pager payloads are generally displayed in a separate pane, that can be viewed alongside code,
410 Pager payloads are generally displayed in a separate pane, that can be viewed alongside code,
411 and are not included in notebook documents.
411 and are not included in notebook documents.
412
412
413 .. sourcecode:: python
413 .. sourcecode:: python
414
414
415 {
415 {
416 "source": "page",
416 "source": "page",
417 # mime-bundle of data to display in the pager.
417 # mime-bundle of data to display in the pager.
418 # Must include text/plain.
418 # Must include text/plain.
419 "data": mimebundle,
419 "data": mimebundle,
420 # line offset to start from
420 # line offset to start from
421 "start": int,
421 "start": int,
422 }
422 }
423
423
424 **set_next_input**: create a new output
424 **set_next_input**: create a new output
425
425
426 used to create new cells in the notebook,
426 used to create new cells in the notebook,
427 or set the next input in a console interface.
427 or set the next input in a console interface.
428 The main example being ``%load``.
428 The main example being ``%load``.
429
429
430 .. sourcecode:: python
430 .. sourcecode:: python
431
431
432 {
432 {
433 "source": "set_next_input",
433 "source": "set_next_input",
434 # the text contents of the cell to create
434 # the text contents of the cell to create
435 "text": "some cell content",
435 "text": "some cell content",
436 # If true, replace the current cell in document UIs instead of inserting
436 # If true, replace the current cell in document UIs instead of inserting
437 # a cell. Ignored in console UIs.
437 # a cell. Ignored in console UIs.
438 "replace": bool,
438 "replace": bool,
439 }
439 }
440
440
441 **edit**: open a file for editing.
441 **edit**: open a file for editing.
442
442
443 Triggered by `%edit`. Only the QtConsole currently supports edit payloads.
443 Triggered by `%edit`. Only the QtConsole currently supports edit payloads.
444
444
445 .. sourcecode:: python
445 .. sourcecode:: python
446
446
447 {
447 {
448 "source": "edit",
448 "source": "edit",
449 "filename": "/path/to/file.py", # the file to edit
449 "filename": "/path/to/file.py", # the file to edit
450 "line_number": int, # the line number to start with
450 "line_number": int, # the line number to start with
451 }
451 }
452
452
453 **ask_exit**: instruct the frontend to prompt the user for exit
453 **ask_exit**: instruct the frontend to prompt the user for exit
454
454
455 Allows the kernel to request exit, e.g. via ``%exit`` in IPython.
455 Allows the kernel to request exit, e.g. via ``%exit`` in IPython.
456 Only for console frontends.
456 Only for console frontends.
457
457
458 .. sourcecode:: python
458 .. sourcecode:: python
459
459
460 {
460 {
461 "source": "ask_exit",
461 "source": "ask_exit",
462 # whether the kernel should be left running, only closing the client
462 # whether the kernel should be left running, only closing the client
463 "keepkernel": bool,
463 "keepkernel": bool,
464 }
464 }
465
465
466
466
467 .. _msging_inspection:
467 .. _msging_inspection:
468
468
469 Introspection
469 Introspection
470 -------------
470 -------------
471
471
472 Code can be inspected to show useful information to the user.
472 Code can be inspected to show useful information to the user.
473 It is up to the Kernel to decide what information should be displayed, and its formatting.
473 It is up to the Kernel to decide what information should be displayed, and its formatting.
474
474
475 Message type: ``inspect_request``::
475 Message type: ``inspect_request``::
476
476
477 content = {
477 content = {
478 # The code context in which introspection is requested
478 # The code context in which introspection is requested
479 # this may be up to an entire multiline cell.
479 # this may be up to an entire multiline cell.
480 'code' : str,
480 'code' : str,
481
481
482 # The cursor position within 'code' (in unicode characters) where inspection is requested
482 # The cursor position within 'code' (in unicode characters) where inspection is requested
483 'cursor_pos' : int,
483 'cursor_pos' : int,
484
484
485 # The level of detail desired. In IPython, the default (0) is equivalent to typing
485 # The level of detail desired. In IPython, the default (0) is equivalent to typing
486 # 'x?' at the prompt, 1 is equivalent to 'x??'.
486 # 'x?' at the prompt, 1 is equivalent to 'x??'.
487 # The difference is up to kernels, but in IPython level 1 includes the source code
487 # The difference is up to kernels, but in IPython level 1 includes the source code
488 # if available.
488 # if available.
489 'detail_level' : 0 or 1,
489 'detail_level' : 0 or 1,
490 }
490 }
491
491
492 .. versionchanged:: 5.0
492 .. versionchanged:: 5.0
493
493
494 ``object_info_request`` renamed to ``inspect_request``.
494 ``object_info_request`` renamed to ``inspect_request``.
495
495
496 .. versionchanged:: 5.0
496 .. versionchanged:: 5.0
497
497
498 ``name`` key replaced with ``code`` and ``cursor_pos``,
498 ``name`` key replaced with ``code`` and ``cursor_pos``,
499 moving the lexing responsibility to the kernel.
499 moving the lexing responsibility to the kernel.
500
500
501 The reply is a mime-bundle, like a `display_data`_ message,
501 The reply is a mime-bundle, like a `display_data`_ message,
502 which should be a formatted representation of information about the context.
502 which should be a formatted representation of information about the context.
503 In the notebook, this is used to show tooltips over function calls, etc.
503 In the notebook, this is used to show tooltips over function calls, etc.
504
504
505 Message type: ``inspect_reply``::
505 Message type: ``inspect_reply``::
506
506
507 content = {
507 content = {
508 # 'ok' if the request succeeded or 'error', with error information as in all other replies.
508 # 'ok' if the request succeeded or 'error', with error information as in all other replies.
509 'status' : 'ok',
509 'status' : 'ok',
510
510
511 # found should be true if an object was found, false otherwise
512 'found' : bool,
513
511 # data can be empty if nothing is found
514 # data can be empty if nothing is found
512 'data' : dict,
515 'data' : dict,
513 'metadata' : dict,
516 'metadata' : dict,
514 }
517 }
515
518
516 .. versionchanged:: 5.0
519 .. versionchanged:: 5.0
517
520
518 ``object_info_reply`` renamed to ``inspect_reply``.
521 ``object_info_reply`` renamed to ``inspect_reply``.
519
522
520 .. versionchanged:: 5.0
523 .. versionchanged:: 5.0
521
524
522 Reply is changed from structured data to a mime bundle, allowing formatting decisions to be made by the kernel.
525 Reply is changed from structured data to a mime bundle, allowing formatting decisions to be made by the kernel.
523
526
524 .. _msging_completion:
527 .. _msging_completion:
525
528
526 Completion
529 Completion
527 ----------
530 ----------
528
531
529 Message type: ``complete_request``::
532 Message type: ``complete_request``::
530
533
531 content = {
534 content = {
532 # The code context in which completion is requested
535 # The code context in which completion is requested
533 # this may be up to an entire multiline cell, such as
536 # this may be up to an entire multiline cell, such as
534 # 'foo = a.isal'
537 # 'foo = a.isal'
535 'code' : str,
538 'code' : str,
536
539
537 # The cursor position within 'code' (in unicode characters) where completion is requested
540 # The cursor position within 'code' (in unicode characters) where completion is requested
538 'cursor_pos' : int,
541 'cursor_pos' : int,
539 }
542 }
540
543
541 .. versionchanged:: 5.0
544 .. versionchanged:: 5.0
542
545
543 ``line``, ``block``, and ``text`` keys are removed in favor of a single ``code`` for context.
546 ``line``, ``block``, and ``text`` keys are removed in favor of a single ``code`` for context.
544 Lexing is up to the kernel.
547 Lexing is up to the kernel.
545
548
546
549
547 Message type: ``complete_reply``::
550 Message type: ``complete_reply``::
548
551
549 content = {
552 content = {
550 # The list of all matches to the completion request, such as
553 # The list of all matches to the completion request, such as
551 # ['a.isalnum', 'a.isalpha'] for the above example.
554 # ['a.isalnum', 'a.isalpha'] for the above example.
552 'matches' : list,
555 'matches' : list,
553
556
554 # The range of text that should be replaced by the above matches when a completion is accepted.
557 # The range of text that should be replaced by the above matches when a completion is accepted.
555 # typically cursor_end is the same as cursor_pos in the request.
558 # typically cursor_end is the same as cursor_pos in the request.
556 'cursor_start' : int,
559 'cursor_start' : int,
557 'cursor_end' : int,
560 'cursor_end' : int,
558
561
559 # Information that frontend plugins might use for extra display information about completions.
562 # Information that frontend plugins might use for extra display information about completions.
560 'metadata' : dict,
563 'metadata' : dict,
561
564
562 # status should be 'ok' unless an exception was raised during the request,
565 # status should be 'ok' unless an exception was raised during the request,
563 # in which case it should be 'error', along with the usual error message content
566 # in which case it should be 'error', along with the usual error message content
564 # in other messages.
567 # in other messages.
565 'status' : 'ok'
568 'status' : 'ok'
566 }
569 }
567
570
568 .. versionchanged:: 5.0
571 .. versionchanged:: 5.0
569
572
570 - ``matched_text`` is removed in favor of ``cursor_start`` and ``cursor_end``.
573 - ``matched_text`` is removed in favor of ``cursor_start`` and ``cursor_end``.
571 - ``metadata`` is added for extended information.
574 - ``metadata`` is added for extended information.
572
575
573 .. _msging_history:
576 .. _msging_history:
574
577
575 History
578 History
576 -------
579 -------
577
580
578 For clients to explicitly request history from a kernel. The kernel has all
581 For clients to explicitly request history from a kernel. The kernel has all
579 the actual execution history stored in a single location, so clients can
582 the actual execution history stored in a single location, so clients can
580 request it from the kernel when needed.
583 request it from the kernel when needed.
581
584
582 Message type: ``history_request``::
585 Message type: ``history_request``::
583
586
584 content = {
587 content = {
585
588
586 # If True, also return output history in the resulting dict.
589 # If True, also return output history in the resulting dict.
587 'output' : bool,
590 'output' : bool,
588
591
589 # If True, return the raw input history, else the transformed input.
592 # If True, return the raw input history, else the transformed input.
590 'raw' : bool,
593 'raw' : bool,
591
594
592 # So far, this can be 'range', 'tail' or 'search'.
595 # So far, this can be 'range', 'tail' or 'search'.
593 'hist_access_type' : str,
596 'hist_access_type' : str,
594
597
595 # If hist_access_type is 'range', get a range of input cells. session can
598 # If hist_access_type is 'range', get a range of input cells. session can
596 # be a positive session number, or a negative number to count back from
599 # be a positive session number, or a negative number to count back from
597 # the current session.
600 # the current session.
598 'session' : int,
601 'session' : int,
599 # start and stop are line numbers within that session.
602 # start and stop are line numbers within that session.
600 'start' : int,
603 'start' : int,
601 'stop' : int,
604 'stop' : int,
602
605
603 # If hist_access_type is 'tail' or 'search', get the last n cells.
606 # If hist_access_type is 'tail' or 'search', get the last n cells.
604 'n' : int,
607 'n' : int,
605
608
606 # If hist_access_type is 'search', get cells matching the specified glob
609 # If hist_access_type is 'search', get cells matching the specified glob
607 # pattern (with * and ? as wildcards).
610 # pattern (with * and ? as wildcards).
608 'pattern' : str,
611 'pattern' : str,
609
612
610 # If hist_access_type is 'search' and unique is true, do not
613 # If hist_access_type is 'search' and unique is true, do not
611 # include duplicated history. Default is false.
614 # include duplicated history. Default is false.
612 'unique' : bool,
615 'unique' : bool,
613
616
614 }
617 }
615
618
616 .. versionadded:: 4.0
619 .. versionadded:: 4.0
617 The key ``unique`` for ``history_request``.
620 The key ``unique`` for ``history_request``.
618
621
619 Message type: ``history_reply``::
622 Message type: ``history_reply``::
620
623
621 content = {
624 content = {
622 # A list of 3 tuples, either:
625 # A list of 3 tuples, either:
623 # (session, line_number, input) or
626 # (session, line_number, input) or
624 # (session, line_number, (input, output)),
627 # (session, line_number, (input, output)),
625 # depending on whether output was False or True, respectively.
628 # depending on whether output was False or True, respectively.
626 'history' : list,
629 'history' : list,
627 }
630 }
628
631
629 .. _msging_is_complete:
632 .. _msging_is_complete:
630
633
631 Code completeness
634 Code completeness
632 -----------------
635 -----------------
633
636
634 .. versionadded:: 5.0
637 .. versionadded:: 5.0
635
638
636 When the user enters a line in a console style interface, the console must
639 When the user enters a line in a console style interface, the console must
637 decide whether to immediately execute the current code, or whether to show a
640 decide whether to immediately execute the current code, or whether to show a
638 continuation prompt for further input. For instance, in Python ``a = 5`` would
641 continuation prompt for further input. For instance, in Python ``a = 5`` would
639 be executed immediately, while ``for i in range(5):`` would expect further input.
642 be executed immediately, while ``for i in range(5):`` would expect further input.
640
643
641 There are four possible replies:
644 There are four possible replies:
642
645
643 - *complete* code is ready to be executed
646 - *complete* code is ready to be executed
644 - *incomplete* code should prompt for another line
647 - *incomplete* code should prompt for another line
645 - *invalid* code will typically be sent for execution, so that the user sees the
648 - *invalid* code will typically be sent for execution, so that the user sees the
646 error soonest.
649 error soonest.
647 - *unknown* - if the kernel is not able to determine this. The frontend should
650 - *unknown* - if the kernel is not able to determine this. The frontend should
648 also handle the kernel not replying promptly. It may default to sending the
651 also handle the kernel not replying promptly. It may default to sending the
649 code for execution, or it may implement simple fallback heuristics for whether
652 code for execution, or it may implement simple fallback heuristics for whether
650 to execute the code (e.g. execute after a blank line).
653 to execute the code (e.g. execute after a blank line).
651
654
652 Frontends may have ways to override this, forcing the code to be sent for
655 Frontends may have ways to override this, forcing the code to be sent for
653 execution or forcing a continuation prompt.
656 execution or forcing a continuation prompt.
654
657
655 Message type: ``is_complete_request``::
658 Message type: ``is_complete_request``::
656
659
657 content = {
660 content = {
658 # The code entered so far as a multiline string
661 # The code entered so far as a multiline string
659 'code' : str,
662 'code' : str,
660 }
663 }
661
664
662 Message type: ``is_complete_reply``::
665 Message type: ``is_complete_reply``::
663
666
664 content = {
667 content = {
665 # One of 'complete', 'incomplete', 'invalid', 'unknown'
668 # One of 'complete', 'incomplete', 'invalid', 'unknown'
666 'status' : str,
669 'status' : str,
667
670
668 # If status is 'incomplete', indent should contain the characters to use
671 # If status is 'incomplete', indent should contain the characters to use
669 # to indent the next line. This is only a hint: frontends may ignore it
672 # to indent the next line. This is only a hint: frontends may ignore it
670 # and use their own autoindentation rules. For other statuses, this
673 # and use their own autoindentation rules. For other statuses, this
671 # field does not exist.
674 # field does not exist.
672 'indent': str,
675 'indent': str,
673 }
676 }
674
677
675 Connect
678 Connect
676 -------
679 -------
677
680
678 When a client connects to the request/reply socket of the kernel, it can issue
681 When a client connects to the request/reply socket of the kernel, it can issue
679 a connect request to get basic information about the kernel, such as the ports
682 a connect request to get basic information about the kernel, such as the ports
680 the other ZeroMQ sockets are listening on. This allows clients to only have
683 the other ZeroMQ sockets are listening on. This allows clients to only have
681 to know about a single port (the shell channel) to connect to a kernel.
684 to know about a single port (the shell channel) to connect to a kernel.
682
685
683 Message type: ``connect_request``::
686 Message type: ``connect_request``::
684
687
685 content = {
688 content = {
686 }
689 }
687
690
688 Message type: ``connect_reply``::
691 Message type: ``connect_reply``::
689
692
690 content = {
693 content = {
691 'shell_port' : int, # The port the shell ROUTER socket is listening on.
694 'shell_port' : int, # The port the shell ROUTER socket is listening on.
692 'iopub_port' : int, # The port the PUB socket is listening on.
695 'iopub_port' : int, # The port the PUB socket is listening on.
693 'stdin_port' : int, # The port the stdin ROUTER socket is listening on.
696 'stdin_port' : int, # The port the stdin ROUTER socket is listening on.
694 'hb_port' : int, # The port the heartbeat socket is listening on.
697 'hb_port' : int, # The port the heartbeat socket is listening on.
695 }
698 }
696
699
697 .. _msging_kernel_info:
700 .. _msging_kernel_info:
698
701
699 Kernel info
702 Kernel info
700 -----------
703 -----------
701
704
702 If a client needs to know information about the kernel, it can
705 If a client needs to know information about the kernel, it can
703 make a request of the kernel's information.
706 make a request of the kernel's information.
704 This message can be used to fetch core information of the
707 This message can be used to fetch core information of the
705 kernel, including language (e.g., Python), language version number and
708 kernel, including language (e.g., Python), language version number and
706 IPython version number, and the IPython message spec version number.
709 IPython version number, and the IPython message spec version number.
707
710
708 Message type: ``kernel_info_request``::
711 Message type: ``kernel_info_request``::
709
712
710 content = {
713 content = {
711 }
714 }
712
715
713 Message type: ``kernel_info_reply``::
716 Message type: ``kernel_info_reply``::
714
717
715 content = {
718 content = {
716 # Version of messaging protocol.
719 # Version of messaging protocol.
717 # The first integer indicates major version. It is incremented when
720 # The first integer indicates major version. It is incremented when
718 # there is any backward incompatible change.
721 # there is any backward incompatible change.
719 # The second integer indicates minor version. It is incremented when
722 # The second integer indicates minor version. It is incremented when
720 # there is any backward compatible change.
723 # there is any backward compatible change.
721 'protocol_version': 'X.Y.Z',
724 'protocol_version': 'X.Y.Z',
722
725
723 # The kernel implementation name
726 # The kernel implementation name
724 # (e.g. 'ipython' for the IPython kernel)
727 # (e.g. 'ipython' for the IPython kernel)
725 'implementation': str,
728 'implementation': str,
726
729
727 # Implementation version number.
730 # Implementation version number.
728 # The version number of the kernel's implementation
731 # The version number of the kernel's implementation
729 # (e.g. IPython.__version__ for the IPython kernel)
732 # (e.g. IPython.__version__ for the IPython kernel)
730 'implementation_version': 'X.Y.Z',
733 'implementation_version': 'X.Y.Z',
731
734
732 # Information about the language of code for the kernel
735 # Information about the language of code for the kernel
733 'language_info': {
736 'language_info': {
734 # Name of the programming language in which kernel is implemented.
737 # Name of the programming language in which kernel is implemented.
735 # Kernel included in IPython returns 'python'.
738 # Kernel included in IPython returns 'python'.
736 'name': str,
739 'name': str,
737
740
738 # Language version number.
741 # Language version number.
739 # It is Python version number (e.g., '2.7.3') for the kernel
742 # It is Python version number (e.g., '2.7.3') for the kernel
740 # included in IPython.
743 # included in IPython.
741 'version': 'X.Y.Z',
744 'version': 'X.Y.Z',
742
745
743 # mimetype for script files in this language
746 # mimetype for script files in this language
744 'mimetype': str,
747 'mimetype': str,
745
748
746 # Extension including the dot, e.g. '.py'
749 # Extension including the dot, e.g. '.py'
747 'file_extension': str,
750 'file_extension': str,
748
751
749 # Pygments lexer, for highlighting
752 # Pygments lexer, for highlighting
750 # Only needed if it differs from the top level 'language' field.
753 # Only needed if it differs from the top level 'language' field.
751 'pygments_lexer': str,
754 'pygments_lexer': str,
752
755
753 # Codemirror mode, for for highlighting in the notebook.
756 # Codemirror mode, for for highlighting in the notebook.
754 # Only needed if it differs from the top level 'language' field.
757 # Only needed if it differs from the top level 'language' field.
755 'codemirror_mode': str or dict,
758 'codemirror_mode': str or dict,
756
759
757 # Nbconvert exporter, if notebooks written with this kernel should
760 # Nbconvert exporter, if notebooks written with this kernel should
758 # be exported with something other than the general 'script'
761 # be exported with something other than the general 'script'
759 # exporter.
762 # exporter.
760 'nbconvert_exporter': str,
763 'nbconvert_exporter': str,
761 },
764 },
762
765
763 # A banner of information about the kernel,
766 # A banner of information about the kernel,
764 # which may be desplayed in console environments.
767 # which may be desplayed in console environments.
765 'banner' : str,
768 'banner' : str,
766
769
767 # Optional: A list of dictionaries, each with keys 'text' and 'url'.
770 # Optional: A list of dictionaries, each with keys 'text' and 'url'.
768 # These will be displayed in the help menu in the notebook UI.
771 # These will be displayed in the help menu in the notebook UI.
769 'help_links': [
772 'help_links': [
770 {'text': str, 'url': str}
773 {'text': str, 'url': str}
771 ],
774 ],
772 }
775 }
773
776
774 Refer to the lists of available `Pygments lexers <http://pygments.org/docs/lexers/>`_
777 Refer to the lists of available `Pygments lexers <http://pygments.org/docs/lexers/>`_
775 and `codemirror modes <http://codemirror.net/mode/index.html>`_ for those fields.
778 and `codemirror modes <http://codemirror.net/mode/index.html>`_ for those fields.
776
779
777 .. versionchanged:: 5.0
780 .. versionchanged:: 5.0
778
781
779 Versions changed from lists of integers to strings.
782 Versions changed from lists of integers to strings.
780
783
781 .. versionchanged:: 5.0
784 .. versionchanged:: 5.0
782
785
783 ``ipython_version`` is removed.
786 ``ipython_version`` is removed.
784
787
785 .. versionchanged:: 5.0
788 .. versionchanged:: 5.0
786
789
787 ``language_info``, ``implementation``, ``implementation_version``, ``banner``
790 ``language_info``, ``implementation``, ``implementation_version``, ``banner``
788 and ``help_links`` keys are added.
791 and ``help_links`` keys are added.
789
792
790 .. versionchanged:: 5.0
793 .. versionchanged:: 5.0
791
794
792 ``language_version`` moved to ``language_info.version``
795 ``language_version`` moved to ``language_info.version``
793
796
794 .. versionchanged:: 5.0
797 .. versionchanged:: 5.0
795
798
796 ``language`` moved to ``language_info.name``
799 ``language`` moved to ``language_info.name``
797
800
798 .. _msging_shutdown:
801 .. _msging_shutdown:
799
802
800 Kernel shutdown
803 Kernel shutdown
801 ---------------
804 ---------------
802
805
803 The clients can request the kernel to shut itself down; this is used in
806 The clients can request the kernel to shut itself down; this is used in
804 multiple cases:
807 multiple cases:
805
808
806 - when the user chooses to close the client application via a menu or window
809 - when the user chooses to close the client application via a menu or window
807 control.
810 control.
808 - when the user types 'exit' or 'quit' (or their uppercase magic equivalents).
811 - when the user types 'exit' or 'quit' (or their uppercase magic equivalents).
809 - when the user chooses a GUI method (like the 'Ctrl-C' shortcut in the
812 - when the user chooses a GUI method (like the 'Ctrl-C' shortcut in the
810 IPythonQt client) to force a kernel restart to get a clean kernel without
813 IPythonQt client) to force a kernel restart to get a clean kernel without
811 losing client-side state like history or inlined figures.
814 losing client-side state like history or inlined figures.
812
815
813 The client sends a shutdown request to the kernel, and once it receives the
816 The client sends a shutdown request to the kernel, and once it receives the
814 reply message (which is otherwise empty), it can assume that the kernel has
817 reply message (which is otherwise empty), it can assume that the kernel has
815 completed shutdown safely.
818 completed shutdown safely.
816
819
817 Upon their own shutdown, client applications will typically execute a last
820 Upon their own shutdown, client applications will typically execute a last
818 minute sanity check and forcefully terminate any kernel that is still alive, to
821 minute sanity check and forcefully terminate any kernel that is still alive, to
819 avoid leaving stray processes in the user's machine.
822 avoid leaving stray processes in the user's machine.
820
823
821 Message type: ``shutdown_request``::
824 Message type: ``shutdown_request``::
822
825
823 content = {
826 content = {
824 'restart' : bool # whether the shutdown is final, or precedes a restart
827 'restart' : bool # whether the shutdown is final, or precedes a restart
825 }
828 }
826
829
827 Message type: ``shutdown_reply``::
830 Message type: ``shutdown_reply``::
828
831
829 content = {
832 content = {
830 'restart' : bool # whether the shutdown is final, or precedes a restart
833 'restart' : bool # whether the shutdown is final, or precedes a restart
831 }
834 }
832
835
833 .. Note::
836 .. Note::
834
837
835 When the clients detect a dead kernel thanks to inactivity on the heartbeat
838 When the clients detect a dead kernel thanks to inactivity on the heartbeat
836 socket, they simply send a forceful process termination signal, since a dead
839 socket, they simply send a forceful process termination signal, since a dead
837 process is unlikely to respond in any useful way to messages.
840 process is unlikely to respond in any useful way to messages.
838
841
839
842
840 Messages on the PUB/SUB socket
843 Messages on the PUB/SUB socket
841 ==============================
844 ==============================
842
845
843 Streams (stdout, stderr, etc)
846 Streams (stdout, stderr, etc)
844 ------------------------------
847 ------------------------------
845
848
846 Message type: ``stream``::
849 Message type: ``stream``::
847
850
848 content = {
851 content = {
849 # The name of the stream is one of 'stdout', 'stderr'
852 # The name of the stream is one of 'stdout', 'stderr'
850 'name' : str,
853 'name' : str,
851
854
852 # The text is an arbitrary string to be written to that stream
855 # The text is an arbitrary string to be written to that stream
853 'text' : str,
856 'text' : str,
854 }
857 }
855
858
856 .. versionchanged:: 5.0
859 .. versionchanged:: 5.0
857
860
858 'data' key renamed to 'text' for conistency with the notebook format.
861 'data' key renamed to 'text' for conistency with the notebook format.
859
862
860 Display Data
863 Display Data
861 ------------
864 ------------
862
865
863 This type of message is used to bring back data that should be displayed (text,
866 This type of message is used to bring back data that should be displayed (text,
864 html, svg, etc.) in the frontends. This data is published to all frontends.
867 html, svg, etc.) in the frontends. This data is published to all frontends.
865 Each message can have multiple representations of the data; it is up to the
868 Each message can have multiple representations of the data; it is up to the
866 frontend to decide which to use and how. A single message should contain all
869 frontend to decide which to use and how. A single message should contain all
867 possible representations of the same information. Each representation should
870 possible representations of the same information. Each representation should
868 be a JSON'able data structure, and should be a valid MIME type.
871 be a JSON'able data structure, and should be a valid MIME type.
869
872
870 Some questions remain about this design:
873 Some questions remain about this design:
871
874
872 * Do we use this message type for execute_result/displayhook? Probably not, because
875 * Do we use this message type for execute_result/displayhook? Probably not, because
873 the displayhook also has to handle the Out prompt display. On the other hand
876 the displayhook also has to handle the Out prompt display. On the other hand
874 we could put that information into the metadata section.
877 we could put that information into the metadata section.
875
878
876 .. _display_data:
879 .. _display_data:
877
880
878 Message type: ``display_data``::
881 Message type: ``display_data``::
879
882
880 content = {
883 content = {
881
884
882 # Who create the data
885 # Who create the data
883 'source' : str,
886 'source' : str,
884
887
885 # The data dict contains key/value pairs, where the keys are MIME
888 # The data dict contains key/value pairs, where the keys are MIME
886 # types and the values are the raw data of the representation in that
889 # types and the values are the raw data of the representation in that
887 # format.
890 # format.
888 'data' : dict,
891 'data' : dict,
889
892
890 # Any metadata that describes the data
893 # Any metadata that describes the data
891 'metadata' : dict
894 'metadata' : dict
892 }
895 }
893
896
894
897
895 The ``metadata`` contains any metadata that describes the output.
898 The ``metadata`` contains any metadata that describes the output.
896 Global keys are assumed to apply to the output as a whole.
899 Global keys are assumed to apply to the output as a whole.
897 The ``metadata`` dict can also contain mime-type keys, which will be sub-dictionaries,
900 The ``metadata`` dict can also contain mime-type keys, which will be sub-dictionaries,
898 which are interpreted as applying only to output of that type.
901 which are interpreted as applying only to output of that type.
899 Third parties should put any data they write into a single dict
902 Third parties should put any data they write into a single dict
900 with a reasonably unique name to avoid conflicts.
903 with a reasonably unique name to avoid conflicts.
901
904
902 The only metadata keys currently defined in IPython are the width and height
905 The only metadata keys currently defined in IPython are the width and height
903 of images::
906 of images::
904
907
905 metadata = {
908 metadata = {
906 'image/png' : {
909 'image/png' : {
907 'width': 640,
910 'width': 640,
908 'height': 480
911 'height': 480
909 }
912 }
910 }
913 }
911
914
912
915
913 .. versionchanged:: 5.0
916 .. versionchanged:: 5.0
914
917
915 `application/json` data should be unpacked JSON data,
918 `application/json` data should be unpacked JSON data,
916 not double-serialized as a JSON string.
919 not double-serialized as a JSON string.
917
920
918
921
919 Raw Data Publication
922 Raw Data Publication
920 --------------------
923 --------------------
921
924
922 ``display_data`` lets you publish *representations* of data, such as images and html.
925 ``display_data`` lets you publish *representations* of data, such as images and html.
923 This ``data_pub`` message lets you publish *actual raw data*, sent via message buffers.
926 This ``data_pub`` message lets you publish *actual raw data*, sent via message buffers.
924
927
925 data_pub messages are constructed via the :func:`IPython.lib.datapub.publish_data` function:
928 data_pub messages are constructed via the :func:`IPython.lib.datapub.publish_data` function:
926
929
927 .. sourcecode:: python
930 .. sourcecode:: python
928
931
929 from IPython.kernel.zmq.datapub import publish_data
932 from IPython.kernel.zmq.datapub import publish_data
930 ns = dict(x=my_array)
933 ns = dict(x=my_array)
931 publish_data(ns)
934 publish_data(ns)
932
935
933
936
934 Message type: ``data_pub``::
937 Message type: ``data_pub``::
935
938
936 content = {
939 content = {
937 # the keys of the data dict, after it has been unserialized
940 # the keys of the data dict, after it has been unserialized
938 'keys' : ['a', 'b']
941 'keys' : ['a', 'b']
939 }
942 }
940 # the namespace dict will be serialized in the message buffers,
943 # the namespace dict will be serialized in the message buffers,
941 # which will have a length of at least one
944 # which will have a length of at least one
942 buffers = [b'pdict', ...]
945 buffers = [b'pdict', ...]
943
946
944
947
945 The interpretation of a sequence of data_pub messages for a given parent request should be
948 The interpretation of a sequence of data_pub messages for a given parent request should be
946 to update a single namespace with subsequent results.
949 to update a single namespace with subsequent results.
947
950
948 .. note::
951 .. note::
949
952
950 No frontends directly handle data_pub messages at this time.
953 No frontends directly handle data_pub messages at this time.
951 It is currently only used by the client/engines in :mod:`IPython.parallel`,
954 It is currently only used by the client/engines in :mod:`IPython.parallel`,
952 where engines may publish *data* to the Client,
955 where engines may publish *data* to the Client,
953 of which the Client can then publish *representations* via ``display_data``
956 of which the Client can then publish *representations* via ``display_data``
954 to various frontends.
957 to various frontends.
955
958
956 Code inputs
959 Code inputs
957 -----------
960 -----------
958
961
959 To let all frontends know what code is being executed at any given time, these
962 To let all frontends know what code is being executed at any given time, these
960 messages contain a re-broadcast of the ``code`` portion of an
963 messages contain a re-broadcast of the ``code`` portion of an
961 :ref:`execute_request <execute>`, along with the :ref:`execution_count
964 :ref:`execute_request <execute>`, along with the :ref:`execution_count
962 <execution_counter>`.
965 <execution_counter>`.
963
966
964 Message type: ``execute_input``::
967 Message type: ``execute_input``::
965
968
966 content = {
969 content = {
967 'code' : str, # Source code to be executed, one or more lines
970 'code' : str, # Source code to be executed, one or more lines
968
971
969 # The counter for this execution is also provided so that clients can
972 # The counter for this execution is also provided so that clients can
970 # display it, since IPython automatically creates variables called _iN
973 # display it, since IPython automatically creates variables called _iN
971 # (for input prompt In[N]).
974 # (for input prompt In[N]).
972 'execution_count' : int
975 'execution_count' : int
973 }
976 }
974
977
975 .. versionchanged:: 5.0
978 .. versionchanged:: 5.0
976
979
977 ``pyin`` is renamed to ``execute_input``.
980 ``pyin`` is renamed to ``execute_input``.
978
981
979
982
980 Execution results
983 Execution results
981 -----------------
984 -----------------
982
985
983 Results of an execution are published as an ``execute_result``.
986 Results of an execution are published as an ``execute_result``.
984 These are identical to `display_data`_ messages, with the addition of an ``execution_count`` key.
987 These are identical to `display_data`_ messages, with the addition of an ``execution_count`` key.
985
988
986 Results can have multiple simultaneous formats depending on its
989 Results can have multiple simultaneous formats depending on its
987 configuration. A plain text representation should always be provided
990 configuration. A plain text representation should always be provided
988 in the ``text/plain`` mime-type. Frontends are free to display any or all of these
991 in the ``text/plain`` mime-type. Frontends are free to display any or all of these
989 according to its capabilities.
992 according to its capabilities.
990 Frontends should ignore mime-types they do not understand. The data itself is
993 Frontends should ignore mime-types they do not understand. The data itself is
991 any JSON object and depends on the format. It is often, but not always a string.
994 any JSON object and depends on the format. It is often, but not always a string.
992
995
993 Message type: ``execute_result``::
996 Message type: ``execute_result``::
994
997
995 content = {
998 content = {
996
999
997 # The counter for this execution is also provided so that clients can
1000 # The counter for this execution is also provided so that clients can
998 # display it, since IPython automatically creates variables called _N
1001 # display it, since IPython automatically creates variables called _N
999 # (for prompt N).
1002 # (for prompt N).
1000 'execution_count' : int,
1003 'execution_count' : int,
1001
1004
1002 # data and metadata are identical to a display_data message.
1005 # data and metadata are identical to a display_data message.
1003 # the object being displayed is that passed to the display hook,
1006 # the object being displayed is that passed to the display hook,
1004 # i.e. the *result* of the execution.
1007 # i.e. the *result* of the execution.
1005 'data' : dict,
1008 'data' : dict,
1006 'metadata' : dict,
1009 'metadata' : dict,
1007 }
1010 }
1008
1011
1009 Execution errors
1012 Execution errors
1010 ----------------
1013 ----------------
1011
1014
1012 When an error occurs during code execution
1015 When an error occurs during code execution
1013
1016
1014 Message type: ``error``::
1017 Message type: ``error``::
1015
1018
1016 content = {
1019 content = {
1017 # Similar content to the execute_reply messages for the 'error' case,
1020 # Similar content to the execute_reply messages for the 'error' case,
1018 # except the 'status' field is omitted.
1021 # except the 'status' field is omitted.
1019 }
1022 }
1020
1023
1021 .. versionchanged:: 5.0
1024 .. versionchanged:: 5.0
1022
1025
1023 ``pyerr`` renamed to ``error``
1026 ``pyerr`` renamed to ``error``
1024
1027
1025 Kernel status
1028 Kernel status
1026 -------------
1029 -------------
1027
1030
1028 This message type is used by frontends to monitor the status of the kernel.
1031 This message type is used by frontends to monitor the status of the kernel.
1029
1032
1030 Message type: ``status``::
1033 Message type: ``status``::
1031
1034
1032 content = {
1035 content = {
1033 # When the kernel starts to handle a message, it will enter the 'busy'
1036 # When the kernel starts to handle a message, it will enter the 'busy'
1034 # state and when it finishes, it will enter the 'idle' state.
1037 # state and when it finishes, it will enter the 'idle' state.
1035 # The kernel will publish state 'starting' exactly once at process startup.
1038 # The kernel will publish state 'starting' exactly once at process startup.
1036 execution_state : ('busy', 'idle', 'starting')
1039 execution_state : ('busy', 'idle', 'starting')
1037 }
1040 }
1038
1041
1039 .. versionchanged:: 5.0
1042 .. versionchanged:: 5.0
1040
1043
1041 Busy and idle messages should be sent before/after handling every message,
1044 Busy and idle messages should be sent before/after handling every message,
1042 not just execution.
1045 not just execution.
1043
1046
1044 .. note::
1047 .. note::
1045
1048
1046 Extra status messages are added between the notebook webserver and websocket clients
1049 Extra status messages are added between the notebook webserver and websocket clients
1047 that are not sent by the kernel. These are:
1050 that are not sent by the kernel. These are:
1048
1051
1049 - restarting (kernel has died, but will be automatically restarted)
1052 - restarting (kernel has died, but will be automatically restarted)
1050 - dead (kernel has died, restarting has failed)
1053 - dead (kernel has died, restarting has failed)
1051
1054
1052 Clear output
1055 Clear output
1053 ------------
1056 ------------
1054
1057
1055 This message type is used to clear the output that is visible on the frontend.
1058 This message type is used to clear the output that is visible on the frontend.
1056
1059
1057 Message type: ``clear_output``::
1060 Message type: ``clear_output``::
1058
1061
1059 content = {
1062 content = {
1060
1063
1061 # Wait to clear the output until new output is available. Clears the
1064 # Wait to clear the output until new output is available. Clears the
1062 # existing output immediately before the new output is displayed.
1065 # existing output immediately before the new output is displayed.
1063 # Useful for creating simple animations with minimal flickering.
1066 # Useful for creating simple animations with minimal flickering.
1064 'wait' : bool,
1067 'wait' : bool,
1065 }
1068 }
1066
1069
1067 .. versionchanged:: 4.1
1070 .. versionchanged:: 4.1
1068
1071
1069 ``stdout``, ``stderr``, and ``display`` boolean keys for selective clearing are removed,
1072 ``stdout``, ``stderr``, and ``display`` boolean keys for selective clearing are removed,
1070 and ``wait`` is added.
1073 and ``wait`` is added.
1071 The selective clearing keys are ignored in v4 and the default behavior remains the same,
1074 The selective clearing keys are ignored in v4 and the default behavior remains the same,
1072 so v4 clear_output messages will be safely handled by a v4.1 frontend.
1075 so v4 clear_output messages will be safely handled by a v4.1 frontend.
1073
1076
1074
1077
1075 Messages on the stdin ROUTER/DEALER sockets
1078 Messages on the stdin ROUTER/DEALER sockets
1076 ===========================================
1079 ===========================================
1077
1080
1078 This is a socket where the request/reply pattern goes in the opposite direction:
1081 This is a socket where the request/reply pattern goes in the opposite direction:
1079 from the kernel to a *single* frontend, and its purpose is to allow
1082 from the kernel to a *single* frontend, and its purpose is to allow
1080 ``raw_input`` and similar operations that read from ``sys.stdin`` on the kernel
1083 ``raw_input`` and similar operations that read from ``sys.stdin`` on the kernel
1081 to be fulfilled by the client. The request should be made to the frontend that
1084 to be fulfilled by the client. The request should be made to the frontend that
1082 made the execution request that prompted ``raw_input`` to be called. For now we
1085 made the execution request that prompted ``raw_input`` to be called. For now we
1083 will keep these messages as simple as possible, since they only mean to convey
1086 will keep these messages as simple as possible, since they only mean to convey
1084 the ``raw_input(prompt)`` call.
1087 the ``raw_input(prompt)`` call.
1085
1088
1086 Message type: ``input_request``::
1089 Message type: ``input_request``::
1087
1090
1088 content = {
1091 content = {
1089 # the text to show at the prompt
1092 # the text to show at the prompt
1090 'prompt' : str,
1093 'prompt' : str,
1091 # Is the request for a password?
1094 # Is the request for a password?
1092 # If so, the frontend shouldn't echo input.
1095 # If so, the frontend shouldn't echo input.
1093 'password' : bool
1096 'password' : bool
1094 }
1097 }
1095
1098
1096 Message type: ``input_reply``::
1099 Message type: ``input_reply``::
1097
1100
1098 content = { 'value' : str }
1101 content = { 'value' : str }
1099
1102
1100
1103
1101 When ``password`` is True, the frontend should not echo the input as it is entered.
1104 When ``password`` is True, the frontend should not echo the input as it is entered.
1102
1105
1103 .. versionchanged:: 5.0
1106 .. versionchanged:: 5.0
1104
1107
1105 ``password`` key added.
1108 ``password`` key added.
1106
1109
1107 .. note::
1110 .. note::
1108
1111
1109 The stdin socket of the client is required to have the same zmq IDENTITY
1112 The stdin socket of the client is required to have the same zmq IDENTITY
1110 as the client's shell socket.
1113 as the client's shell socket.
1111 Because of this, the ``input_request`` must be sent with the same IDENTITY
1114 Because of this, the ``input_request`` must be sent with the same IDENTITY
1112 routing prefix as the ``execute_reply`` in order for the frontend to receive
1115 routing prefix as the ``execute_reply`` in order for the frontend to receive
1113 the message.
1116 the message.
1114
1117
1115 .. note::
1118 .. note::
1116
1119
1117 We do not explicitly try to forward the raw ``sys.stdin`` object, because in
1120 We do not explicitly try to forward the raw ``sys.stdin`` object, because in
1118 practice the kernel should behave like an interactive program. When a
1121 practice the kernel should behave like an interactive program. When a
1119 program is opened on the console, the keyboard effectively takes over the
1122 program is opened on the console, the keyboard effectively takes over the
1120 ``stdin`` file descriptor, and it can't be used for raw reading anymore.
1123 ``stdin`` file descriptor, and it can't be used for raw reading anymore.
1121 Since the IPython kernel effectively behaves like a console program (albeit
1124 Since the IPython kernel effectively behaves like a console program (albeit
1122 one whose "keyboard" is actually living in a separate process and
1125 one whose "keyboard" is actually living in a separate process and
1123 transported over the zmq connection), raw ``stdin`` isn't expected to be
1126 transported over the zmq connection), raw ``stdin`` isn't expected to be
1124 available.
1127 available.
1125
1128
1126 .. _kernel_heartbeat:
1129 .. _kernel_heartbeat:
1127
1130
1128 Heartbeat for kernels
1131 Heartbeat for kernels
1129 =====================
1132 =====================
1130
1133
1131 Clients send ping messages on a REQ socket, which are echoed right back
1134 Clients send ping messages on a REQ socket, which are echoed right back
1132 from the Kernel's REP socket. These are simple bytestrings, not full JSON messages described above.
1135 from the Kernel's REP socket. These are simple bytestrings, not full JSON messages described above.
1133
1136
1134
1137
1135 Custom Messages
1138 Custom Messages
1136 ===============
1139 ===============
1137
1140
1138 .. versionadded:: 4.1
1141 .. versionadded:: 4.1
1139
1142
1140 IPython 2.0 (msgspec v4.1) adds a messaging system for developers to add their own objects with Frontend
1143 IPython 2.0 (msgspec v4.1) adds a messaging system for developers to add their own objects with Frontend
1141 and Kernel-side components, and allow them to communicate with each other.
1144 and Kernel-side components, and allow them to communicate with each other.
1142 To do this, IPython adds a notion of a ``Comm``, which exists on both sides,
1145 To do this, IPython adds a notion of a ``Comm``, which exists on both sides,
1143 and can communicate in either direction.
1146 and can communicate in either direction.
1144
1147
1145 These messages are fully symmetrical - both the Kernel and the Frontend can send each message,
1148 These messages are fully symmetrical - both the Kernel and the Frontend can send each message,
1146 and no messages expect a reply.
1149 and no messages expect a reply.
1147 The Kernel listens for these messages on the Shell channel,
1150 The Kernel listens for these messages on the Shell channel,
1148 and the Frontend listens for them on the IOPub channel.
1151 and the Frontend listens for them on the IOPub channel.
1149
1152
1150 Opening a Comm
1153 Opening a Comm
1151 --------------
1154 --------------
1152
1155
1153 Opening a Comm produces a ``comm_open`` message, to be sent to the other side::
1156 Opening a Comm produces a ``comm_open`` message, to be sent to the other side::
1154
1157
1155 {
1158 {
1156 'comm_id' : 'u-u-i-d',
1159 'comm_id' : 'u-u-i-d',
1157 'target_name' : 'my_comm',
1160 'target_name' : 'my_comm',
1158 'data' : {}
1161 'data' : {}
1159 }
1162 }
1160
1163
1161 Every Comm has an ID and a target name.
1164 Every Comm has an ID and a target name.
1162 The code handling the message on the receiving side is responsible for maintaining a mapping
1165 The code handling the message on the receiving side is responsible for maintaining a mapping
1163 of target_name keys to constructors.
1166 of target_name keys to constructors.
1164 After a ``comm_open`` message has been sent,
1167 After a ``comm_open`` message has been sent,
1165 there should be a corresponding Comm instance on both sides.
1168 there should be a corresponding Comm instance on both sides.
1166 The ``data`` key is always a dict and can be any extra JSON information used in initialization of the comm.
1169 The ``data`` key is always a dict and can be any extra JSON information used in initialization of the comm.
1167
1170
1168 If the ``target_name`` key is not found on the receiving side,
1171 If the ``target_name`` key is not found on the receiving side,
1169 then it should immediately reply with a ``comm_close`` message to avoid an inconsistent state.
1172 then it should immediately reply with a ``comm_close`` message to avoid an inconsistent state.
1170
1173
1171 Comm Messages
1174 Comm Messages
1172 -------------
1175 -------------
1173
1176
1174 Comm messages are one-way communications to update comm state,
1177 Comm messages are one-way communications to update comm state,
1175 used for synchronizing widget state, or simply requesting actions of a comm's counterpart.
1178 used for synchronizing widget state, or simply requesting actions of a comm's counterpart.
1176
1179
1177 Essentially, each comm pair defines their own message specification implemented inside the ``data`` dict.
1180 Essentially, each comm pair defines their own message specification implemented inside the ``data`` dict.
1178
1181
1179 There are no expected replies (of course, one side can send another ``comm_msg`` in reply).
1182 There are no expected replies (of course, one side can send another ``comm_msg`` in reply).
1180
1183
1181 Message type: ``comm_msg``::
1184 Message type: ``comm_msg``::
1182
1185
1183 {
1186 {
1184 'comm_id' : 'u-u-i-d',
1187 'comm_id' : 'u-u-i-d',
1185 'data' : {}
1188 'data' : {}
1186 }
1189 }
1187
1190
1188 Tearing Down Comms
1191 Tearing Down Comms
1189 ------------------
1192 ------------------
1190
1193
1191 Since comms live on both sides, when a comm is destroyed the other side must be notified.
1194 Since comms live on both sides, when a comm is destroyed the other side must be notified.
1192 This is done with a ``comm_close`` message.
1195 This is done with a ``comm_close`` message.
1193
1196
1194 Message type: ``comm_close``::
1197 Message type: ``comm_close``::
1195
1198
1196 {
1199 {
1197 'comm_id' : 'u-u-i-d',
1200 'comm_id' : 'u-u-i-d',
1198 'data' : {}
1201 'data' : {}
1199 }
1202 }
1200
1203
1201 Output Side Effects
1204 Output Side Effects
1202 -------------------
1205 -------------------
1203
1206
1204 Since comm messages can execute arbitrary user code,
1207 Since comm messages can execute arbitrary user code,
1205 handlers should set the parent header and publish status busy / idle,
1208 handlers should set the parent header and publish status busy / idle,
1206 just like an execute request.
1209 just like an execute request.
1207
1210
1208
1211
1209 To Do
1212 To Do
1210 =====
1213 =====
1211
1214
1212 Missing things include:
1215 Missing things include:
1213
1216
1214 * Important: finish thinking through the payload concept and API.
1217 * Important: finish thinking through the payload concept and API.
1215
1218
1216 .. include:: ../links.txt
1219 .. include:: ../links.txt
General Comments 0
You need to be logged in to leave comments. Login now