##// END OF EJS Templates
Merge branch 'stdin'...
MinRK -
r4954:6e92ffd9 merge
parent child Browse files
Show More
@@ -6,6 +6,7 b' Authors:'
6
6
7 * Brian Granger
7 * Brian Granger
8 * Fernando Perez
8 * Fernando Perez
9 * Min Ragan-Kelley
9
10
10 Notes
11 Notes
11 -----
12 -----
@@ -49,3 +50,10 b' class UsageError(IPythonCoreError):'
49 Something that probably won't warrant a full traceback, but should
50 Something that probably won't warrant a full traceback, but should
50 nevertheless interrupt a macro / batch file.
51 nevertheless interrupt a macro / batch file.
51 """
52 """
53
54 class StdinNotImplementedError(IPythonCoreError, NotImplementedError):
55 """raw_input was requested in a context where it is not supported
56
57 For use in IPython kernels, where only some frontends may support
58 stdin requests.
59 """
@@ -1546,7 +1546,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1546 # line, there may be SyntaxError cases with imported code.
1546 # line, there may be SyntaxError cases with imported code.
1547 self.showsyntaxerror(filename)
1547 self.showsyntaxerror(filename)
1548 elif etype is UsageError:
1548 elif etype is UsageError:
1549 print "UsageError:", value
1549 self.write_err("UsageError: %s" % value)
1550 else:
1550 else:
1551 # WARNING: these variables are somewhat deprecated and not
1551 # WARNING: these variables are somewhat deprecated and not
1552 # necessarily safe to use in a threaded environment, but tools
1552 # necessarily safe to use in a threaded environment, but tools
@@ -121,6 +121,7 b' var IPython = (function (IPython) {'
121 silent : false,
121 silent : false,
122 user_variables : [],
122 user_variables : [],
123 user_expressions : {}
123 user_expressions : {}
124 allow_stdin : false,
124 };
125 };
125 var msg = this.get_msg("execute_request", content);
126 var msg = this.get_msg("execute_request", content);
126 this.shell_channel.send(JSON.stringify(msg));
127 this.shell_channel.send(JSON.stringify(msg));
@@ -29,6 +29,7 b' import zmq'
29 from IPython.config.configurable import Configurable
29 from IPython.config.configurable import Configurable
30 from IPython.config.application import boolean_flag
30 from IPython.config.application import boolean_flag
31 from IPython.core.application import ProfileDir
31 from IPython.core.application import ProfileDir
32 from IPython.core.error import StdinNotImplementedError
32 from IPython.core.shellapp import (
33 from IPython.core.shellapp import (
33 InteractiveShellApp, shell_flags, shell_aliases
34 InteractiveShellApp, shell_flags, shell_aliases
34 )
35 )
@@ -219,7 +220,11 b' class Kernel(Configurable):'
219
220
220 # Replace raw_input. Note that is not sufficient to replace
221 # Replace raw_input. Note that is not sufficient to replace
221 # raw_input in the user namespace.
222 # raw_input in the user namespace.
222 raw_input = lambda prompt='': self._raw_input(prompt, ident, parent)
223 if content.get('allow_stdin', False):
224 raw_input = lambda prompt='': self._raw_input(prompt, ident, parent)
225 else:
226 raw_input = lambda prompt='' : self._no_raw_input()
227
223 if py3compat.PY3:
228 if py3compat.PY3:
224 __builtin__.input = raw_input
229 __builtin__.input = raw_input
225 else:
230 else:
@@ -406,6 +411,10 b' class Kernel(Configurable):'
406 # be set shorter for true asynchronous clients.
411 # be set shorter for true asynchronous clients.
407 time.sleep(0.1)
412 time.sleep(0.1)
408
413
414 def _no_raw_input(self):
415 """Raise StdinNotImplentedError if active frontend doesn't support stdin."""
416 raise StdinNotImplementedError("raw_input was called, but this frontend does not support stdin.")
417
409 def _raw_input(self, prompt, ident, parent):
418 def _raw_input(self, prompt, ident, parent):
410 # Flush output before making the request.
419 # Flush output before making the request.
411 sys.stderr.flush()
420 sys.stderr.flush()
@@ -413,7 +422,7 b' class Kernel(Configurable):'
413
422
414 # Send the input request.
423 # Send the input request.
415 content = json_clean(dict(prompt=prompt))
424 content = json_clean(dict(prompt=prompt))
416 msg = self.session.send(self.stdin_socket, u'input_request', content, parent)
425 msg = self.session.send(self.stdin_socket, u'input_request', content, parent, ident=ident)
417
426
418 # Await a response.
427 # Await a response.
419 while True:
428 while True:
@@ -153,9 +153,9 b' class KernelApp(BaseIPythonApplication):'
153 self.iopub_port = self._bind_socket(self.iopub_socket, self.iopub_port)
153 self.iopub_port = self._bind_socket(self.iopub_socket, self.iopub_port)
154 self.log.debug("iopub PUB Channel on port: %i"%self.iopub_port)
154 self.log.debug("iopub PUB Channel on port: %i"%self.iopub_port)
155
155
156 self.stdin_socket = context.socket(zmq.XREQ)
156 self.stdin_socket = context.socket(zmq.ROUTER)
157 self.stdin_port = self._bind_socket(self.stdin_socket, self.stdin_port)
157 self.stdin_port = self._bind_socket(self.stdin_socket, self.stdin_port)
158 self.log.debug("stdin XREQ Channel on port: %i"%self.stdin_port)
158 self.log.debug("stdin ROUTER Channel on port: %i"%self.stdin_port)
159
159
160 self.heartbeat = Heartbeat(context, (self.ip, self.hb_port))
160 self.heartbeat = Heartbeat(context, (self.ip, self.hb_port))
161 self.hb_port = self.heartbeat.port
161 self.hb_port = self.heartbeat.port
@@ -179,6 +179,8 b' class ShellSocketChannel(ZMQSocketChannel):'
179 """
179 """
180
180
181 command_queue = None
181 command_queue = None
182 # flag for whether execute requests should be allowed to call raw_input:
183 allow_stdin = True
182
184
183 def __init__(self, context, session, address):
185 def __init__(self, context, session, address):
184 super(ShellSocketChannel, self).__init__(context, session, address)
186 super(ShellSocketChannel, self).__init__(context, session, address)
@@ -210,7 +212,7 b' class ShellSocketChannel(ZMQSocketChannel):'
210 raise NotImplementedError('call_handlers must be defined in a subclass.')
212 raise NotImplementedError('call_handlers must be defined in a subclass.')
211
213
212 def execute(self, code, silent=False,
214 def execute(self, code, silent=False,
213 user_variables=None, user_expressions=None):
215 user_variables=None, user_expressions=None, allow_stdin=None):
214 """Execute code in the kernel.
216 """Execute code in the kernel.
215
217
216 Parameters
218 Parameters
@@ -231,6 +233,12 b' class ShellSocketChannel(ZMQSocketChannel):'
231 namespace. They will come back as a dict with these names as keys
233 namespace. They will come back as a dict with these names as keys
232 and their :func:`repr` as values.
234 and their :func:`repr` as values.
233
235
236 allow_stdin : bool, optional
237 Flag for
238 A dict with string keys and to pull from the user's
239 namespace. They will come back as a dict with these names as keys
240 and their :func:`repr` as values.
241
234 Returns
242 Returns
235 -------
243 -------
236 The msg_id of the message sent.
244 The msg_id of the message sent.
@@ -239,7 +247,10 b' class ShellSocketChannel(ZMQSocketChannel):'
239 user_variables = []
247 user_variables = []
240 if user_expressions is None:
248 if user_expressions is None:
241 user_expressions = {}
249 user_expressions = {}
242
250 if allow_stdin is None:
251 allow_stdin = self.allow_stdin
252
253
243 # Don't waste network traffic if inputs are invalid
254 # Don't waste network traffic if inputs are invalid
244 if not isinstance(code, basestring):
255 if not isinstance(code, basestring):
245 raise ValueError('code %r must be a string' % code)
256 raise ValueError('code %r must be a string' % code)
@@ -250,7 +261,9 b' class ShellSocketChannel(ZMQSocketChannel):'
250 # not in Session.
261 # not in Session.
251 content = dict(code=code, silent=silent,
262 content = dict(code=code, silent=silent,
252 user_variables=user_variables,
263 user_variables=user_variables,
253 user_expressions=user_expressions)
264 user_expressions=user_expressions,
265 allow_stdin=allow_stdin,
266 )
254 msg = self.session.msg('execute_request', content)
267 msg = self.session.msg('execute_request', content)
255 self._queue_request(msg)
268 self._queue_request(msg)
256 return msg['header']['msg_id']
269 return msg['header']['msg_id']
@@ -735,6 +748,9 b' class KernelManager(HasTraits):'
735 self.sub_channel.start()
748 self.sub_channel.start()
736 if stdin:
749 if stdin:
737 self.stdin_channel.start()
750 self.stdin_channel.start()
751 self.shell_channel.allow_stdin = True
752 else:
753 self.shell_channel.allow_stdin = False
738 if hb:
754 if hb:
739 self.hb_channel.start()
755 self.hb_channel.start()
740
756
@@ -209,7 +209,7 b' class Kernel(HasTraits):'
209
209
210 # Send the input request.
210 # Send the input request.
211 content = dict(prompt=prompt)
211 content = dict(prompt=prompt)
212 msg = self.session.send(self.stdin_socket, u'input_request', content, parent)
212 msg = self.session.send(self.stdin_socket, u'input_request', content, parent, ident=ident)
213
213
214 # Await a response.
214 # Await a response.
215 ident,reply = self.session.recv(self.stdin_socket, 0)
215 ident,reply = self.session.recv(self.stdin_socket, 0)
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -14,8 +14,8 b''
14 height="1052.3622047"
14 height="1052.3622047"
15 id="svg2"
15 id="svg2"
16 version="1.1"
16 version="1.1"
17 inkscape:version="0.47 r22583"
17 inkscape:version="0.48.2 r9819"
18 sodipodi:docname="ipython-frontend-kernel.svg"
18 sodipodi:docname="frontend-kernel.svg"
19 inkscape:export-filename="/home/jtriley/Documents/ipython-frontend-kernel.png"
19 inkscape:export-filename="/home/jtriley/Documents/ipython-frontend-kernel.png"
20 inkscape:export-xdpi="90"
20 inkscape:export-xdpi="90"
21 inkscape:export-ydpi="90">
21 inkscape:export-ydpi="90">
@@ -2956,17 +2956,17 b''
2956 inkscape:pageshadow="2"
2956 inkscape:pageshadow="2"
2957 inkscape:zoom="0.90509668"
2957 inkscape:zoom="0.90509668"
2958 inkscape:cx="256.73404"
2958 inkscape:cx="256.73404"
2959 inkscape:cy="303.39911"
2959 inkscape:cy="-403.70767"
2960 inkscape:document-units="px"
2960 inkscape:document-units="px"
2961 inkscape:current-layer="layer1"
2961 inkscape:current-layer="layer1"
2962 showgrid="false"
2962 showgrid="false"
2963 showguides="true"
2963 showguides="true"
2964 inkscape:guide-bbox="true"
2964 inkscape:guide-bbox="true"
2965 inkscape:window-width="1440"
2965 inkscape:window-width="1245"
2966 inkscape:window-height="825"
2966 inkscape:window-height="756"
2967 inkscape:window-x="0"
2967 inkscape:window-x="0"
2968 inkscape:window-y="24"
2968 inkscape:window-y="0"
2969 inkscape:window-maximized="1"
2969 inkscape:window-maximized="0"
2970 inkscape:snap-nodes="true" />
2970 inkscape:snap-nodes="true" />
2971 <metadata
2971 <metadata
2972 id="metadata7">
2972 id="metadata7">
@@ -3022,7 +3022,7 b''
3022 <rect
3022 <rect
3023 style="fill:#241c1c;fill-opacity:1"
3023 style="fill:#241c1c;fill-opacity:1"
3024 id="rect4235"
3024 id="rect4235"
3025 width="151.52289"
3025 width="180"
3026 height="92.934036"
3026 height="92.934036"
3027 x="43.015251"
3027 x="43.015251"
3028 y="565.53973"
3028 y="565.53973"
@@ -3032,7 +3032,7 b''
3032 <rect
3032 <rect
3033 style="fill:#008000;fill-opacity:1"
3033 style="fill:#008000;fill-opacity:1"
3034 id="rect4235-2"
3034 id="rect4235-2"
3035 width="151.52289"
3035 width="180"
3036 height="92.934036"
3036 height="92.934036"
3037 x="285.4671"
3037 x="285.4671"
3038 y="565.53973"
3038 y="565.53973"
@@ -3052,7 +3052,7 b''
3052 <text
3052 <text
3053 xml:space="preserve"
3053 xml:space="preserve"
3054 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3054 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3055 x="75.632164"
3055 x="49.632164"
3056 y="624.2724"
3056 y="624.2724"
3057 id="text4268"
3057 id="text4268"
3058 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3058 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
@@ -3060,13 +3060,13 b''
3060 inkscape:export-ydpi="90"><tspan
3060 inkscape:export-ydpi="90"><tspan
3061 sodipodi:role="line"
3061 sodipodi:role="line"
3062 id="tspan4270"
3062 id="tspan4270"
3063 x="75.632164"
3063 x="49.632164"
3064 y="624.2724"
3064 y="624.2724"
3065 style="fill:#ffffff">REQ</tspan></text>
3065 style="fill:#ffffff">ROUTER</tspan></text>
3066 <text
3066 <text
3067 xml:space="preserve"
3067 xml:space="preserve"
3068 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3068 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3069 x="308.98245"
3069 x="292.98245"
3070 y="626.58685"
3070 y="626.58685"
3071 id="text4268-9"
3071 id="text4268-9"
3072 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3072 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
@@ -3074,9 +3074,9 b''
3074 inkscape:export-ydpi="90"><tspan
3074 inkscape:export-ydpi="90"><tspan
3075 sodipodi:role="line"
3075 sodipodi:role="line"
3076 id="tspan4270-1"
3076 id="tspan4270-1"
3077 x="308.98245"
3077 x="292.98245"
3078 y="626.58685"
3078 y="626.58685"
3079 style="fill:#ffffff">XREP</tspan></text>
3079 style="fill:#ffffff">ROUTER</tspan></text>
3080 <text
3080 <text
3081 xml:space="preserve"
3081 xml:space="preserve"
3082 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3082 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
@@ -3148,13 +3148,14 b''
3148 y="222.01678" /></flowRegion><flowPara
3148 y="222.01678" /></flowRegion><flowPara
3149 id="flowPara3620"
3149 id="flowPara3620"
3150 style="font-size:28px;font-weight:bold">Front-end</flowPara></flowRoot> <path
3150 style="font-size:28px;font-weight:bold">Front-end</flowPara></flowRoot> <path
3151 style="fill:#05ff00;stroke:#2af510;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none;fill-opacity:1"
3151 style="fill:#05ff00;fill-opacity:1;stroke:#2af510;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
3152 d="m 373.73648,243.10253 -0.11904,-45.00016"
3152 d="m 373.73648,243.10253 -0.11904,-45.00016"
3153 id="path3711"
3153 id="path3711"
3154 inkscape:connector-type="polyline"
3154 inkscape:connector-type="polyline"
3155 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3155 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3156 inkscape:export-xdpi="90"
3156 inkscape:export-xdpi="90"
3157 inkscape:export-ydpi="90" />
3157 inkscape:export-ydpi="90"
3158 inkscape:connector-curvature="0" />
3158 <rect
3159 <rect
3159 style="fill:#00ff00;fill-opacity:1"
3160 style="fill:#00ff00;fill-opacity:1"
3160 id="rect3884"
3161 id="rect3884"
@@ -3192,7 +3193,7 b''
3192 <text
3193 <text
3193 xml:space="preserve"
3194 xml:space="preserve"
3194 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3195 style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
3195 x="454.03732"
3196 x="444.03732"
3196 y="345.68896"
3197 y="345.68896"
3197 id="text4861-2"
3198 id="text4861-2"
3198 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3199 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
@@ -3200,9 +3201,9 b''
3200 inkscape:export-ydpi="90"><tspan
3201 inkscape:export-ydpi="90"><tspan
3201 sodipodi:role="line"
3202 sodipodi:role="line"
3202 id="tspan4863-6"
3203 id="tspan4863-6"
3203 x="454.03732"
3204 x="444.03732"
3204 y="345.68896"
3205 y="345.68896"
3205 style="font-size:28px;fill:#ffffff">REP</tspan></text>
3206 style="font-size:28px;fill:#ffffff">DEAL</tspan></text>
3206 <rect
3207 <rect
3207 style="fill:#ff0000;fill-opacity:1"
3208 style="fill:#ff0000;fill-opacity:1"
3208 id="rect4859-9-4"
3209 id="rect4859-9-4"
@@ -3250,7 +3251,7 b''
3250 id="tspan4863-6-97"
3251 id="tspan4863-6-97"
3251 x="239.47998"
3252 x="239.47998"
3252 y="344.35312"
3253 y="344.35312"
3253 style="font-size:28px;fill:#ffffff">XREQ</tspan></text>
3254 style="font-size:28px;fill:#ffffff">DEAL</tspan></text>
3254 <rect
3255 <rect
3255 style="fill:#0000ff;fill-rule:evenodd;stroke:#000000;stroke-width:0.80252945px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
3256 style="fill:#0000ff;fill-rule:evenodd;stroke:#000000;stroke-width:0.80252945px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
3256 id="rect2816-3"
3257 id="rect2816-3"
@@ -3281,7 +3282,8 b''
3281 style="fill:none;stroke:#06ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
3282 style="fill:none;stroke:#06ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
3282 d="m 728.27256,243.10253 -0.1191,-45.00015"
3283 d="m 728.27256,243.10253 -0.1191,-45.00015"
3283 id="path3711-4"
3284 id="path3711-4"
3284 inkscape:connector-type="polyline" />
3285 inkscape:connector-type="polyline"
3286 inkscape:connector-curvature="0" />
3285 <rect
3287 <rect
3286 style="fill:#00ff00;fill-opacity:1"
3288 style="fill:#00ff00;fill-opacity:1"
3287 id="rect3884-4"
3289 id="rect3884-4"
@@ -3335,7 +3337,7 b''
3335 id="tspan4863-6-97-6"
3337 id="tspan4863-6-97-6"
3336 x="631.95612"
3338 x="631.95612"
3337 y="344.35312"
3339 y="344.35312"
3338 style="font-size:28px;fill:#ffffff">XREQ</tspan></text>
3340 style="font-size:28px;fill:#ffffff">DEAL</tspan></text>
3339 <rect
3341 <rect
3340 style="fill:#0000ff;fill-rule:evenodd;stroke:#000000;stroke-width:0.80252945px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
3342 style="fill:#0000ff;fill-rule:evenodd;stroke:#000000;stroke-width:0.80252945px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
3341 id="rect2816-3-6"
3343 id="rect2816-3-6"
@@ -3367,7 +3369,8 b''
3367 d="m 37.276897,243.10252 -0.11904,-45.00015"
3369 d="m 37.276897,243.10252 -0.11904,-45.00015"
3368 id="path3711-4-8"
3370 id="path3711-4-8"
3369 inkscape:connector-type="polyline"
3371 inkscape:connector-type="polyline"
3370 sodipodi:nodetypes="cc" />
3372 sodipodi:nodetypes="cc"
3373 inkscape:connector-curvature="0" />
3371 <rect
3374 <rect
3372 style="fill:#00ff00;fill-opacity:1"
3375 style="fill:#00ff00;fill-opacity:1"
3373 id="rect3884-4-1"
3376 id="rect3884-4-1"
@@ -3421,10 +3424,10 b''
3421 id="tspan4863-6-97-6-1"
3424 id="tspan4863-6-97-6-1"
3422 x="-59.039528"
3425 x="-59.039528"
3423 y="344.35312"
3426 y="344.35312"
3424 style="font-size:28px;fill:#ffffff">XREQ</tspan></text>
3427 style="font-size:28px;fill:#ffffff">DEAL</tspan></text>
3425 <path
3428 <path
3426 style="fill:#ff0000;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3429 style="fill:#ff0000;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3427 d="m 123.8316,357.91004 355.72174,187.40953 50.81739,26.77279"
3430 d="M 123.8316,357.91004 530.37073,572.09236"
3428 id="path10788"
3431 id="path10788"
3429 inkscape:connector-type="polyline"
3432 inkscape:connector-type="polyline"
3430 inkscape:connection-start="#rect4859-9-4-5-6"
3433 inkscape:connection-start="#rect4859-9-4-5-6"
@@ -3432,10 +3435,13 b''
3432 sodipodi:nodetypes="ccc"
3435 sodipodi:nodetypes="ccc"
3433 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3436 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3434 inkscape:export-xdpi="90"
3437 inkscape:export-xdpi="90"
3435 inkscape:export-ydpi="90" />
3438 inkscape:export-ydpi="90"
3439 inkscape:connection-start-point="d4"
3440 inkscape:connection-end-point="d4"
3441 inkscape:connector-curvature="0" />
3436 <path
3442 <path
3437 style="fill:#d40000;fill-opacity:1;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3443 style="fill:#d40000;fill-opacity:1;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3438 d="M 759.43823,357.91004 696.80284,461.72488 634.16746,565.53973"
3444 d="M 759.43823,357.91004 634.16746,565.53973"
3439 id="path10790"
3445 id="path10790"
3440 inkscape:connector-type="polyline"
3446 inkscape:connector-type="polyline"
3441 inkscape:connection-start="#rect4859-9-4-5"
3447 inkscape:connection-start="#rect4859-9-4-5"
@@ -3443,10 +3449,13 b''
3443 sodipodi:nodetypes="ccc"
3449 sodipodi:nodetypes="ccc"
3444 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3450 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3445 inkscape:export-xdpi="90"
3451 inkscape:export-xdpi="90"
3446 inkscape:export-ydpi="90" />
3452 inkscape:export-ydpi="90"
3453 inkscape:connection-start-point="d4"
3454 inkscape:connection-end-point="d4"
3455 inkscape:connector-curvature="0" />
3447 <path
3456 <path
3448 style="fill:none;stroke:#278900;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3457 style="fill:none;stroke:#278900;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3449 d="M 10.376699,357.91004 297.06778,565.53973"
3458 d="M 11.518036,357.91004 308.91123,565.53973"
3450 id="path10792"
3459 id="path10792"
3451 inkscape:connector-type="polyline"
3460 inkscape:connector-type="polyline"
3452 inkscape:connection-start="#rect4859-9-3-5-8"
3461 inkscape:connection-start="#rect4859-9-3-5-8"
@@ -3454,10 +3463,13 b''
3454 sodipodi:nodetypes="ccc"
3463 sodipodi:nodetypes="ccc"
3455 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3464 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3456 inkscape:export-xdpi="90"
3465 inkscape:export-xdpi="90"
3457 inkscape:export-ydpi="90" />
3466 inkscape:export-ydpi="90"
3467 inkscape:connection-start-point="d4"
3468 inkscape:connection-end-point="d4"
3469 inkscape:connector-curvature="0" />
3458 <path
3470 <path
3459 style="fill:#008000;fill-opacity:1;stroke:#238800;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3471 style="fill:#008000;fill-opacity:1;stroke:#238800;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3460 d="M 645.98339,357.91004 413.30206,565.53973"
3472 d="M 647.12473,357.91004 425.14551,565.53973"
3461 id="path10794"
3473 id="path10794"
3462 inkscape:connector-type="polyline"
3474 inkscape:connector-type="polyline"
3463 inkscape:connection-start="#rect4859-9-3-5"
3475 inkscape:connection-start="#rect4859-9-3-5"
@@ -3465,10 +3477,13 b''
3465 sodipodi:nodetypes="ccc"
3477 sodipodi:nodetypes="ccc"
3466 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3478 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3467 inkscape:export-xdpi="90"
3479 inkscape:export-xdpi="90"
3468 inkscape:export-ydpi="90" />
3480 inkscape:export-ydpi="90"
3481 inkscape:connection-start-point="d4"
3482 inkscape:connection-end-point="d4"
3483 inkscape:connector-curvature="0" />
3469 <path
3484 <path
3470 style="fill:none;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3485 style="fill:none;stroke:#ff0000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mstart)"
3471 d="m 398.42235,357.91004 127.29423,155.72226 42.43141,51.90743"
3486 d="M 398.42235,357.91004 568.14799,565.53973"
3472 id="path10796"
3487 id="path10796"
3473 inkscape:connector-type="polyline"
3488 inkscape:connector-type="polyline"
3474 inkscape:connection-start="#rect4859-9-4"
3489 inkscape:connection-start="#rect4859-9-4"
@@ -3476,10 +3491,13 b''
3476 sodipodi:nodetypes="ccc"
3491 sodipodi:nodetypes="ccc"
3477 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3492 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3478 inkscape:export-xdpi="90"
3493 inkscape:export-xdpi="90"
3479 inkscape:export-ydpi="90" />
3494 inkscape:export-ydpi="90"
3495 inkscape:connection-start-point="d4"
3496 inkscape:connection-end-point="d4"
3497 inkscape:connector-curvature="0" />
3480 <path
3498 <path
3481 style="fill:#280b0b;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:none"
3499 style="fill:#280b0b;stroke:#000000;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:none"
3482 d="M 179.80746,565.53973 452.88606,357.62577"
3500 d="M 191.65337,565.53973 454.02622,357.62577"
3483 id="path10800"
3501 id="path10800"
3484 inkscape:connector-type="polyline"
3502 inkscape:connector-type="polyline"
3485 inkscape:connection-start="#rect4235"
3503 inkscape:connection-start="#rect4235"
@@ -3487,10 +3505,13 b''
3487 sodipodi:nodetypes="ccc"
3505 sodipodi:nodetypes="ccc"
3488 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3506 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3489 inkscape:export-xdpi="90"
3507 inkscape:export-xdpi="90"
3490 inkscape:export-ydpi="90" />
3508 inkscape:export-ydpi="90"
3509 inkscape:connection-start-point="d4"
3510 inkscape:connection-end-point="d4"
3511 inkscape:connector-curvature="0" />
3491 <path
3512 <path
3492 style="fill:#ff0000;stroke:#449900;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mend)"
3513 style="fill:#ff0000;stroke:#449900;stroke-width:4;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-mid:url(#Arrow1Mend)"
3493 d="M 347.28257,565.53973 284.96744,357.91004"
3514 d="M 359.12602,565.53973 286.10878,357.91004"
3494 id="path10802"
3515 id="path10802"
3495 inkscape:connector-type="polyline"
3516 inkscape:connector-type="polyline"
3496 inkscape:connection-start="#rect4235-2"
3517 inkscape:connection-start="#rect4235-2"
@@ -3498,7 +3519,10 b''
3498 sodipodi:nodetypes="ccc"
3519 sodipodi:nodetypes="ccc"
3499 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3520 inkscape:export-filename="/home/jtriley/Documents/path10411-0-4-9.png"
3500 inkscape:export-xdpi="90"
3521 inkscape:export-xdpi="90"
3501 inkscape:export-ydpi="90" />
3522 inkscape:export-ydpi="90"
3523 inkscape:connection-start-point="d4"
3524 inkscape:connection-end-point="d4"
3525 inkscape:connector-curvature="0" />
3502 <rect
3526 <rect
3503 style="fill:#000000;fill-opacity:1;stroke:none"
3527 style="fill:#000000;fill-opacity:1;stroke:none"
3504 id="rect11963"
3528 id="rect11963"
@@ -6717,20 +6741,28 b''
6717 id="path6285"
6741 id="path6285"
6718 inkscape:connector-type="polyline"
6742 inkscape:connector-type="polyline"
6719 inkscape:connection-start="#rect4497"
6743 inkscape:connection-start="#rect4497"
6720 inkscape:connection-end="#rect3695" />
6744 inkscape:connection-end="#rect3695"
6745 inkscape:connection-start-point="d4"
6746 inkscape:connection-end-point="d4"
6747 inkscape:connector-curvature="0" />
6721 <path
6748 <path
6722 style="fill:none;stroke:#07ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
6749 style="fill:none;stroke:#07ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
6723 d="m 728.98863,98.204487 0.69887,46.345193"
6750 d="m 728.98863,98.204487 0.69887,46.345193"
6724 id="path7136"
6751 id="path7136"
6725 inkscape:connector-type="polyline"
6752 inkscape:connector-type="polyline"
6726 inkscape:connection-start="#g6750" />
6753 inkscape:connection-start="#g6750"
6754 inkscape:connection-start-point="d4"
6755 inkscape:connector-curvature="0" />
6727 <path
6756 <path
6728 style="fill:none;stroke:#06ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
6757 style="fill:none;stroke:#06ff00;stroke-width:8;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
6729 d="m 37.066258,97.891987 0.09752,46.781813"
6758 d="m 37.066258,97.891987 0.09752,46.781813"
6730 id="path5028"
6759 id="path5028"
6731 inkscape:connector-type="polyline"
6760 inkscape:connector-type="polyline"
6732 inkscape:connection-end="#rect3695-4-1"
6761 inkscape:connection-end="#rect3695-4-1"
6733 inkscape:connection-start="#g4874" />
6762 inkscape:connection-start="#g4874"
6763 inkscape:connection-start-point="d4"
6764 inkscape:connection-end-point="d4"
6765 inkscape:connector-curvature="0" />
6734 <path
6766 <path
6735 style="fill:none;stroke:#000000;stroke-width:3.20000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-start:url(#Arrow1Send-9);marker-mid:none;marker-end:url(#Arrow1Mend)"
6767 style="fill:none;stroke:#000000;stroke-width:3.20000005;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker-start:url(#Arrow1Send-9);marker-mid:none;marker-end:url(#Arrow1Mend)"
6736 d="m 97.76109,405.78583 c 49.81163,34.41382 20.9084,50.49106 -23.630766,17.69543"
6768 d="m 97.76109,405.78583 c 49.81163,34.41382 20.9084,50.49106 -23.630766,17.69543"
@@ -31,30 +31,30 b' The basic design is explained in the following diagram:'
31 A single kernel can be simultaneously connected to one or more frontends. The
31 A single kernel can be simultaneously connected to one or more frontends. The
32 kernel has three sockets that serve the following functions:
32 kernel has three sockets that serve the following functions:
33
33
34 1. REQ: this socket is connected to a *single* frontend at a time, and it allows
34 1. stdin: this ROUTER socket is connected to all frontends, and it allows
35 the kernel to request input from a frontend when :func:`raw_input` is called.
35 the kernel to request input from the active frontend when :func:`raw_input` is called.
36 The frontend holding the matching REP socket 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 widget or
39 frontends may display such kernel requests using a special input widget 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
43 2. ROUTER: this single sockets allows multiple incoming connections from
43 2. Shell: this single ROUTER socket allows multiple incoming connections from
44 frontends, and this is the socket where requests for code execution, object
44 frontends, and this is the socket where requests for code execution, object
45 information, prompts, etc. are made to the kernel by any frontend. The
45 information, prompts, etc. are made to the kernel by any frontend. The
46 communication on this socket is a sequence of request/reply actions from
46 communication on this socket is a sequence of request/reply actions from
47 each frontend and the kernel.
47 each frontend and the kernel.
48
48
49 3. PUB: this socket is the 'broadcast channel' where the kernel publishes all
49 3. IOPub: this socket is the 'broadcast channel' where the kernel publishes all
50 side effects (stdout, stderr, etc.) as well as the requests coming from any
50 side effects (stdout, stderr, etc.) as well as the requests coming from any
51 client over the ROUTER socket and its own requests on the REP socket. There
51 client over the shell socket and its own requests on the stdin socket. There
52 are a number of actions in Python which generate side effects: :func:`print`
52 are a number of actions in Python which generate side effects: :func:`print`
53 writes to ``sys.stdout``, errors generate tracebacks, etc. Additionally, in
53 writes to ``sys.stdout``, errors generate tracebacks, etc. Additionally, in
54 a multi-client scenario, we want all frontends to be able to know what each
54 a multi-client scenario, we want all frontends to be able to know what each
55 other has sent to the kernel (this can be useful in collaborative scenarios,
55 other has sent to the kernel (this can be useful in collaborative scenarios,
56 for example). This socket allows both side effects and the information
56 for example). This socket allows both side effects and the information
57 about communications taking place with one client over the ROUTER/DEALER channel
57 about communications taking place with one client over the shell channel
58 to be made available to all clients in a uniform manner.
58 to be made available to all clients in a uniform manner.
59
59
60 All messages are tagged with enough information (details below) for clients
60 All messages are tagged with enough information (details below) for clients
@@ -126,8 +126,8 b' For each message type, the actual content will differ and all existing message'
126 types are specified in what follows of this document.
126 types are specified in what follows of this document.
127
127
128
128
129 Messages on the ROUTER/DEALER socket
129 Messages on the shell ROUTER/DEALER sockets
130 ================================
130 ===========================================
131
131
132 .. _execute:
132 .. _execute:
133
133
@@ -162,6 +162,12 b' Message type: ``execute_request``::'
162 # Similarly, a dict mapping names to expressions to be evaluated in the
162 # Similarly, a dict mapping names to expressions to be evaluated in the
163 # user's dict.
163 # user's dict.
164 'user_expressions' : dict,
164 'user_expressions' : dict,
165
166 # Some frontends (e.g. the Notebook) do not support stdin requests. If
167 # raw_input is called from code executed from such a frontend, a
168 # StdinNotImplementedError will be raised.
169 'allow_stdin' : True,
170
165 }
171 }
166
172
167 The ``code`` field contains a single string (possibly multiline). The kernel
173 The ``code`` field contains a single string (possibly multiline). The kernel
@@ -637,7 +643,7 b' Connect'
637 When a client connects to the request/reply socket of the kernel, it can issue
643 When a client connects to the request/reply socket of the kernel, it can issue
638 a connect request to get basic information about the kernel, such as the ports
644 a connect request to get basic information about the kernel, such as the ports
639 the other ZeroMQ sockets are listening on. This allows clients to only have
645 the other ZeroMQ sockets are listening on. This allows clients to only have
640 to know about a single port (the DEALER/ROUTER channel) to connect to a kernel.
646 to know about a single port (the shell channel) to connect to a kernel.
641
647
642 Message type: ``connect_request``::
648 Message type: ``connect_request``::
643
649
@@ -647,9 +653,9 b' Message type: ``connect_request``::'
647 Message type: ``connect_reply``::
653 Message type: ``connect_reply``::
648
654
649 content = {
655 content = {
650 'xrep_port' : int # The port the ROUTER socket is listening on.
656 'shell_port' : int # The port the shell ROUTER socket is listening on.
651 'pub_port' : int # The port the PUB socket is listening on.
657 'iopub_port' : int # The port the PUB socket is listening on.
652 'req_port' : int # The port the REQ socket is listening on.
658 'stdin_port' : int # The port the stdin ROUTER socket is listening on.
653 'hb_port' : int # The port the heartbeat socket is listening on.
659 'hb_port' : int # The port the heartbeat socket is listening on.
654 }
660 }
655
661
@@ -863,15 +869,17 b' Message type: ``file``::'
863 'data' : str,
869 'data' : str,
864 }
870 }
865
871
866
867 Messages on the REQ/REP socket
868 ==============================
869
872
870 This is a socket that goes in the opposite direction: from the kernel to a
873 Messages on the stdin ROUTER/DEALER sockets
871 *single* frontend, and its purpose is to allow ``raw_input`` and similar
874 ===========================================
872 operations that read from ``sys.stdin`` on the kernel to be fulfilled by the
875
873 client. For now we will keep these messages as simple as possible, since they
876 This is a socket where the request/reply pattern goes in the opposite direction:
874 basically only mean to convey the ``raw_input(prompt)`` call.
877 from the kernel to a *single* frontend, and its purpose is to allow
878 ``raw_input`` and similar operations that read from ``sys.stdin`` on the kernel
879 to be fulfilled by the client. The request should be made to the frontend that
880 made the execution request that prompted ``raw_input`` to be called. For now we
881 will keep these messages as simple as possible, since they only mean to convey
882 the ``raw_input(prompt)`` call.
875
883
876 Message type: ``input_request``::
884 Message type: ``input_request``::
877
885
General Comments 0
You need to be logged in to leave comments. Login now