##// END OF EJS Templates
pass on msgspec doc with updates
MinRK -
Show More
@@ -103,6 +103,8 b' A message is defined by the following four-dictionary structure::'
103 103 'session' : uuid,
104 104 # All recognized message type strings are listed below.
105 105 'msg_type' : str,
106 # the message protocol version
107 'version' : '5.0.0',
106 108 },
107 109
108 110 # In a chain of messages, the header from the parent is copied so that
@@ -151,14 +153,14 b' The front of the message is the ZeroMQ routing prefix,'
151 153 which can be zero or more socket identities.
152 154 This is every piece of the message prior to the delimiter key ``<IDS|MSG>``.
153 155 In the case of IOPub, there should be just one prefix component,
154 which is the topic for IOPub subscribers, e.g. ``pyout``, ``display_data``.
156 which is the topic for IOPub subscribers, e.g. ``execute_result``, ``display_data``.
155 157
156 158 .. note::
157 159
158 160 In most cases, the IOPub topics are irrelevant and completely ignored,
159 161 because frontends just subscribe to all topics.
160 162 The convention used in the IPython kernel is to use the msg_type as the topic,
161 and possibly extra information about the message, e.g. ``pyout`` or ``stream.stdout``
163 and possibly extra information about the message, e.g. ``execute_result`` or ``stream.stdout``
162 164
163 165 After the delimiter is the `HMAC`_ signature of the message, used for authentication.
164 166 If authentication is disabled, this should be an empty string.
@@ -263,20 +265,15 b' Message type: ``execute_request``::'
263 265 # is forced to be False.
264 266 'store_history' : bool,
265 267
266 # A list of variable names from the user's namespace to be retrieved.
267 # What returns is a rich representation of each variable (dict keyed by name).
268 # See the display_data content for the structure of the representation data.
269 'user_variables' : list,
270
271 268 # Similarly, a dict mapping names to expressions to be evaluated in the
272 # user's dict.
269 # user's dict. The rich display-data representation of each will be evaluated after execution.
270 # See the display_data content for the structure of the representation data.
273 271 'user_expressions' : dict,
274 272
275 # Some frontends (e.g. the Notebook) do not support stdin requests. If
276 # raw_input is called from code executed from such a frontend, a
277 # StdinNotImplementedError will be raised.
273 # Some frontends do not support stdin requests.
274 # If raw_input is called from code executed from such a frontend,
275 # a StdinNotImplementedError will be raised.
278 276 'allow_stdin' : True,
279
280 277 }
281 278
282 279 The ``code`` field contains a single string (possibly multiline). The kernel
@@ -284,27 +281,23 b' is responsible for splitting this into one or more independent execution blocks'
284 281 and deciding whether to compile these in 'single' or 'exec' mode (see below for
285 282 detailed execution semantics).
286 283
287 The ``user_`` fields deserve a detailed explanation. In the past, IPython had
284 The ``user_expressions`` fields deserve a detailed explanation. In the past, IPython had
288 285 the notion of a prompt string that allowed arbitrary code to be evaluated, and
289 286 this was put to good use by many in creating prompts that displayed system
290 287 status, path information, and even more esoteric uses like remote instrument
291 288 status acquired over the network. But now that IPython has a clean separation
292 289 between the kernel and the clients, the kernel has no prompt knowledge; prompts
293 are a frontend-side feature, and it should be even possible for different
290 are a frontend feature, and it should be even possible for different
294 291 frontends to display different prompts while interacting with the same kernel.
295 292
296 The kernel now provides the ability to retrieve data from the user's namespace
293 The kernel provides the ability to retrieve data from the user's namespace
297 294 after the execution of the main ``code``, thanks to two fields in the
298 295 ``execute_request`` message:
299 296
300 - ``user_variables``: If only variables from the user's namespace are needed, a
301 list of variable names can be passed and a dict with these names as keys and
302 their :func:`repr()` as values will be returned.
303
304 297 - ``user_expressions``: For more complex expressions that require function
305 298 evaluations, a dict can be provided with string keys and arbitrary python
306 299 expressions as values. The return message will contain also a dict with the
307 same keys and the :func:`repr()` of the evaluated expressions as value.
300 same keys and the rich representations of the evaluated expressions as value.
308 301
309 302 With this information, frontends can display any status information they wish
310 303 in the form that best suits each frontend (a status line, a popup, inline for a
@@ -326,9 +319,8 b' following phases (in silent mode, only the ``code`` field is executed):'
326 319
327 320 2. Execute the ``code`` field, see below for details.
328 321
329 3. If #2 succeeds, compute ``user_variables`` and ``user_expressions`` are
330 computed. This ensures that any error in the latter don't harm the main
331 code execution.
322 3. If #2 succeeds, expressions in ``user_expressions`` are computed.
323 This ensures that any error in the expressions don't affect the main code execution.
332 324
333 325 4. Call any method registered with :meth:`register_post_execute`.
334 326
@@ -383,16 +375,17 b" execution in 'single' mode, and then:"
383 375 * otherwise (last one is also multiline), run all in 'exec' mode as a single
384 376 unit.
385 377
386 Any error in retrieving the ``user_variables`` or evaluating the
387 ``user_expressions`` will result in a simple error message in the return fields
388 of the form::
389
390 [ERROR] ExceptionType: Exception message
378 Any error in evaluating any expression in ``user_expressions`` will result in
379 only that key containing a standard error message, of the form::
391 380
392 The user can simply send the same variable name or expression for evaluation to
393 see a regular traceback.
381 {
382 'status' : 'error',
383 'ename' : 'NameError',
384 'evalue' : 'foo',
385 'traceback' : ...
386 }
394 387
395 Errors in any registered post_execute functions are also reported similarly,
388 Errors in any registered post_execute functions are also reported,
396 389 and the failing function is removed from the post_execution set so that it does
397 390 not continue triggering failures.
398 391
@@ -404,8 +397,8 b' codes and associated data.'
404 397
405 398 .. _execution_counter:
406 399
407 Execution counter (old prompt number)
408 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
400 Execution counter (prompt number)
401 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
409 402
410 403 The kernel has a single, monotonically increasing counter of all execution
411 404 requests that are made with ``store_history=True``. This counter is used to populate
@@ -444,15 +437,14 b" When status is 'ok', the following extra fields are present::"
444 437 # which is a string classifying the payload (e.g. 'pager').
445 438 'payload' : list(dict),
446 439
447 # Results for the user_variables and user_expressions.
448 'user_variables' : dict,
440 # Results for the user_expressions.
449 441 'user_expressions' : dict,
450 442 }
451 443
452 444 .. admonition:: Execution payloads
453 445
454 446 The notion of an 'execution payload' is different from a return value of a
455 given set of code, which normally is just displayed on the pyout stream
447 given set of code, which normally is just displayed on the execute_result stream
456 448 through the PUB socket. The idea of a payload is to allow special types of
457 449 code, typically magics, to populate a data container in the IPython kernel
458 450 that will be shipped back to the caller via this channel. The kernel
@@ -748,25 +740,28 b' Message type: ``kernel_info_reply``::'
748 740 # there is any backward incompatible change.
749 741 # The second integer indicates minor version. It is incremented when
750 742 # there is any backward compatible change.
751 'protocol_version': [int, int],
743 'protocol_version': 'X.Y.Z',
752 744
753 745 # IPython version number (optional).
754 746 # Non-python kernel backend may not have this version number.
755 # The last component is an extra field, which may be 'dev' or
756 # 'rc1' in development version. It is an empty string for
757 # released version.
758 'ipython_version': [int, int, int, str],
747 # could be '2.0.0-dev' for development version
748 'ipython_version': 'X.Y.Z',
759 749
760 750 # Language version number (mandatory).
761 # It is Python version number (e.g., [2, 7, 3]) for the kernel
751 # It is Python version number (e.g., '2.7.3') for the kernel
762 752 # included in IPython.
763 'language_version': [int, ...],
753 'language_version': 'X.Y.Z',
764 754
765 755 # Programming language in which kernel is implemented (mandatory).
766 756 # Kernel included in IPython returns 'python'.
767 757 'language': str,
768 758 }
769 759
760 .. versionchanged:: 5.0
761
762 In protocol version 4.0, versions were given as lists of numbers,
763 not version strings.
764
770 765
771 766 Kernel shutdown
772 767 ---------------
@@ -834,6 +829,12 b' frontend to decide which to use and how. A single message should contain all'
834 829 possible representations of the same information. Each representation should
835 830 be a JSON'able data structure, and should be a valid MIME type.
836 831
832 Some questions remain about this design:
833
834 * Do we use this message type for execute_result/displayhook? Probably not, because
835 the displayhook also has to handle the Out prompt display. On the other hand
836 we could put that information into the metadata secion.
837
837 838 Message type: ``display_data``::
838 839
839 840 content = {
@@ -936,7 +937,7 b' the Python interactive prompt is to print to ``sys.stdout`` the :func:`repr` of'
936 937 the value as long as it is not ``None`` (which isn't printed at all). In our
937 938 case, the kernel instantiates as ``sys.displayhook`` an object which has
938 939 similar behavior, but which instead of printing to stdout, broadcasts these
939 values as ``pyout`` messages for clients to display appropriately.
940 values as ``execute_result`` messages for clients to display appropriately.
940 941
941 942 IPython's displayhook can handle multiple simultaneous formats depending on its
942 943 configuration. The default pretty-printed repr text is always given with the
@@ -950,7 +951,7 b' frontend how to interpret the data. It is often, but not always a MIME type.'
950 951 Frontends should ignore types that it does not understand. The data itself is
951 952 any JSON object and depends on the format. It is often, but not always a string.
952 953
953 Message type: ``pyout``::
954 Message type: ``execute_result``::
954 955
955 956 content = {
956 957
@@ -971,7 +972,7 b' Python errors'
971 972
972 973 When an error occurs during code execution
973 974
974 Message type: ``pyerr``::
975 Message type: ``error``::
975 976
976 977 content = {
977 978 # Similar content to the execute_reply messages for the 'error' case,
General Comments 0
You need to be logged in to leave comments. Login now