Show More
@@ -36,7 +36,7 b' kernel has three sockets that serve the following functions:' | |||||
36 | The frontend that executed the code has a DEALER socket that acts as a 'virtual keyboard' |
|
36 | The frontend that executed the code has a DEALER socket that acts as a 'virtual keyboard' | |
37 | for the kernel while this communication is happening (illustrated in the |
|
37 | for the kernel while this communication is happening (illustrated in the | |
38 | figure by the black outline around the central keyboard). In practice, |
|
38 | figure by the black outline around the central keyboard). In practice, | |
39 |
frontends may display such kernel requests using a special input |
|
39 | frontends may display such kernel requests using a special input comm or | |
40 | otherwise indicating that the user is to type input for the kernel instead |
|
40 | otherwise indicating that the user is to type input for the kernel instead | |
41 | of normal commands in the frontend. |
|
41 | of normal commands in the frontend. | |
42 |
|
42 | |||
@@ -1058,65 +1058,79 b" where the first part is the zmq.IDENTITY of the heart's DEALER on the engine, an" | |||||
1058 | the rest is the message sent by the monitor. No Python code ever has any |
|
1058 | the rest is the message sent by the monitor. No Python code ever has any | |
1059 | access to the message between the monitor's send, and the monitor's recv. |
|
1059 | access to the message between the monitor's send, and the monitor's recv. | |
1060 |
|
1060 | |||
1061 |
|
|
1061 | Custom Messages | |
1062 | =============== |
|
1062 | =============== | |
1063 |
|
1063 | |||
1064 | IPython 2.0 adds interactive widgets, and a few messages associated with their management. |
|
1064 | IPython 2.0 adds a messaging system for developers to add their own objects with Frontend | |
1065 | Widget messages are fully symmetrical - both the Kernel and the Frontend can send each message, |
|
1065 | and Kernel-side components, and allow them to communicate with each other. | |
|
1066 | To do this, IPython adds a notion of a ``Comm``, which exists on both sides, | |||
|
1067 | and can communicate in either direction. | |||
|
1068 | ||||
|
1069 | These messages are fully symmetrical - both the Kernel and the Frontend can send each message, | |||
1066 | and no messages expect a reply. |
|
1070 | and no messages expect a reply. | |
1067 | The Kernel listens for these messages on the Shell channel, |
|
1071 | The Kernel listens for these messages on the Shell channel, | |
1068 | and the Frontend listens for them on the IOPub channel. |
|
1072 | and the Frontend listens for them on the IOPub channel. | |
1069 |
|
1073 | |||
1070 | .. versionadded:: 2.0 |
|
1074 | .. versionadded:: 2.0 | |
1071 |
|
1075 | |||
1072 | Widget Creation |
|
1076 | Opening a Comm | |
1073 |
-------------- |
|
1077 | -------------- | |
1074 |
|
1078 | |||
1075 |
|
|
1079 | Opening a Comm produces a ``comm_open`` message, to be sent to the other side:: | |
1076 |
|
1080 | |||
1077 | { |
|
1081 | { | |
1078 |
' |
|
1082 | 'comm_id' : 'u-u-i-d', | |
1079 |
' |
|
1083 | 'target_name' : 'my_comm', | |
1080 | 'data' : {} |
|
1084 | 'data' : {} | |
1081 | } |
|
1085 | } | |
1082 |
|
1086 | |||
1083 |
Every |
|
1087 | Every Comm has an ID and a target name. | |
1084 | The code handling the message on the receiving side is responsible for maintaining a mapping |
|
1088 | The code handling the message on the receiving side is responsible for maintaining a mapping | |
1085 |
of |
|
1089 | of target_name keys to constructors. | |
1086 |
After a `` |
|
1090 | After a ``comm_open`` message has been sent, | |
1087 |
there should be a corresponding |
|
1091 | there should be a corresponding Comm instance on both sides. | |
1088 |
The ``data`` key is always a dict and can be any extra JSON information used in initialization of the |
|
1092 | The ``data`` key is always a dict and can be any extra JSON information used in initialization of the comm. | |
1089 |
|
1093 | |||
1090 | Updating Widgets |
|
1094 | If the ``target_name`` key is not found on the receiving side, | |
1091 | ---------------- |
|
1095 | then it should immediately reply with a ``comm_close`` message to avoid an inconsistent state. | |
|
1096 | ||||
|
1097 | Comm Messages | |||
|
1098 | ------------- | |||
1092 |
|
1099 | |||
1093 |
|
|
1100 | Comm messages are one-way communications to update comm state, | |
1094 |
used for synchronizing state, or simply requesting actions of a |
|
1101 | used for synchronizing widget state, or simply requesting actions of a comm's counterpart. | |
1095 |
|
1102 | |||
1096 |
Essentially, each |
|
1103 | Essentially, each comm pair defines their own message specification implemented inside the ``data`` dict. | |
1097 |
|
1104 | |||
1098 |
There are no expected replies (of course, one side can send another `` |
|
1105 | There are no expected replies (of course, one side can send another ``comm_msg`` in reply). | |
1099 |
|
1106 | |||
1100 |
Message type: `` |
|
1107 | Message type: ``comm_msg``:: | |
1101 |
|
1108 | |||
1102 | { |
|
1109 | { | |
1103 |
' |
|
1110 | 'comm_id' : 'u-u-i-d', | |
1104 | 'data' : {} |
|
1111 | 'data' : {} | |
1105 | } |
|
1112 | } | |
1106 |
|
1113 | |||
1107 |
Tearing Down |
|
1114 | Tearing Down Comms | |
1108 |
------------------ |
|
1115 | ------------------ | |
1109 |
|
1116 | |||
1110 |
Since |
|
1117 | Since comms live on both sides, when a comm is destroyed the other side must be notified. | |
1111 |
This is done with a `` |
|
1118 | This is done with a ``comm_close`` message. | |
1112 |
|
1119 | |||
1113 |
Message type: `` |
|
1120 | Message type: ``comm_close``:: | |
1114 |
|
1121 | |||
1115 | { |
|
1122 | { | |
1116 |
' |
|
1123 | 'comm_id' : 'u-u-i-d', | |
1117 | 'data' : {} |
|
1124 | 'data' : {} | |
1118 | } |
|
1125 | } | |
1119 |
|
1126 | |||
|
1127 | Output Side Effects | |||
|
1128 | ------------------- | |||
|
1129 | ||||
|
1130 | Since comm messages can execute arbitrary user code, | |||
|
1131 | handlers should set the parent header and publish status busy / idle, | |||
|
1132 | just like an execute request. | |||
|
1133 | ||||
1120 |
|
1134 | |||
1121 | ToDo |
|
1135 | ToDo | |
1122 | ==== |
|
1136 | ==== |
General Comments 0
You need to be logged in to leave comments.
Login now