Show More
@@ -216,7 +216,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
216 | 216 | |
|
217 | 217 | See parent class :meth:`execute` docstring for full details. |
|
218 | 218 | """ |
|
219 |
msg_id = self.kernel_client. |
|
|
219 | msg_id = self.kernel_client.execute(source, hidden) | |
|
220 | 220 | self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'user') |
|
221 | 221 | self._hidden = hidden |
|
222 | 222 | if not hidden: |
@@ -358,7 +358,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
358 | 358 | # generate uuid, which would be used as an indication of whether or |
|
359 | 359 | # not the unique request originated from here (can use msg id ?) |
|
360 | 360 | local_uuid = str(uuid.uuid1()) |
|
361 |
msg_id = self.kernel_client. |
|
|
361 | msg_id = self.kernel_client.execute('', | |
|
362 | 362 | silent=True, user_expressions={ local_uuid:expr }) |
|
363 | 363 | self._callback_dict[local_uuid] = callback |
|
364 | 364 | self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'silent_exec_callback') |
@@ -671,7 +671,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
671 | 671 | |
|
672 | 672 | # Send the metadata request to the kernel |
|
673 | 673 | name = '.'.join(context) |
|
674 |
msg_id = self.kernel_client. |
|
|
674 | msg_id = self.kernel_client.object_info(name) | |
|
675 | 675 | pos = self._get_cursor().position() |
|
676 | 676 | self._request_info['call_tip'] = self._CallTipRequest(msg_id, pos) |
|
677 | 677 | return True |
@@ -682,7 +682,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): | |||
|
682 | 682 | context = self._get_context() |
|
683 | 683 | if context: |
|
684 | 684 | # Send the completion request to the kernel |
|
685 |
msg_id = self.kernel_client. |
|
|
685 | msg_id = self.kernel_client.complete( | |
|
686 | 686 | '.'.join(context), # text |
|
687 | 687 | self._get_input_buffer_cursor_line(), # line |
|
688 | 688 | self._get_input_buffer_cursor_column(), # cursor_pos |
@@ -81,6 +81,7 class ZMQSocketChannel(Thread): | |||
|
81 | 81 | stream = None |
|
82 | 82 | _address = None |
|
83 | 83 | _exiting = False |
|
84 | proxy_methods = [] | |
|
84 | 85 | |
|
85 | 86 | def __init__(self, context, session, address): |
|
86 | 87 | """Create a channel. |
@@ -175,6 +176,14 class ShellChannel(ZMQSocketChannel): | |||
|
175 | 176 | command_queue = None |
|
176 | 177 | # flag for whether execute requests should be allowed to call raw_input: |
|
177 | 178 | allow_stdin = True |
|
179 | proxy_methods = [ | |
|
180 | 'execute', | |
|
181 | 'complete', | |
|
182 | 'object_info', | |
|
183 | 'history', | |
|
184 | 'kernel_info', | |
|
185 | 'shutdown', | |
|
186 | ] | |
|
178 | 187 | |
|
179 | 188 | def __init__(self, context, session, address): |
|
180 | 189 | super(ShellChannel, self).__init__(context, session, address) |
@@ -451,6 +460,7 class StdInChannel(ZMQSocketChannel): | |||
|
451 | 460 | """The stdin channel to handle raw_input requests that the kernel makes.""" |
|
452 | 461 | |
|
453 | 462 | msg_queue = None |
|
463 | proxy_methods = ['input'] | |
|
454 | 464 | |
|
455 | 465 | def __init__(self, context, session, address): |
|
456 | 466 | super(StdInChannel, self).__init__(context, session, address) |
@@ -69,6 +69,34 class KernelClient(LoggingConfigurable, ConnectionFileMixin): | |||
|
69 | 69 | _stdin_channel = Any |
|
70 | 70 | _hb_channel = Any |
|
71 | 71 | |
|
72 | # def __init__(self, *args, **kwargs): | |
|
73 | # super(KernelClient, self).__init__(*args, **kwargs) | |
|
74 | # # setup channel proxy methods, e.g. | |
|
75 | # # Client.execute => shell_channel.execute | |
|
76 | # for channel in ['shell', 'iopub', 'stdin', 'hb']: | |
|
77 | # cls = getattr(self, '%s_channel_class' % channel) | |
|
78 | # for method in cls.proxy_methods: | |
|
79 | # setattr(self, method, self._proxy_method(channel, method)) | |
|
80 | # | |
|
81 | #-------------------------------------------------------------------------- | |
|
82 | # Channel proxy methods | |
|
83 | #-------------------------------------------------------------------------- | |
|
84 | ||
|
85 | def _get_msg(channel, *args, **kwargs): | |
|
86 | return channel.get_msg(*args, **kwargs) | |
|
87 | ||
|
88 | def get_shell_msg(self, *args, **kwargs): | |
|
89 | """Get a message from the shell channel""" | |
|
90 | return self.shell_channel.get_msg(*args, **kwargs) | |
|
91 | ||
|
92 | def get_iopub_msg(self, *args, **kwargs): | |
|
93 | """Get a message from the iopub channel""" | |
|
94 | return self.iopub_channel.get_msg(*args, **kwargs) | |
|
95 | ||
|
96 | def get_stdin_msg(self, *args, **kwargs): | |
|
97 | """Get a message from the stdin channel""" | |
|
98 | return self.stdin_channel.get_msg(*args, **kwargs) | |
|
99 | ||
|
72 | 100 | #-------------------------------------------------------------------------- |
|
73 | 101 | # Channel management methods |
|
74 | 102 | #-------------------------------------------------------------------------- |
@@ -84,10 +112,16 class KernelClient(LoggingConfigurable, ConnectionFileMixin): | |||
|
84 | 112 | """ |
|
85 | 113 | if shell: |
|
86 | 114 | self.shell_channel.start() |
|
115 | for method in self.shell_channel.proxy_methods: | |
|
116 | setattr(self, method, getattr(self.shell_channel, method)) | |
|
87 | 117 | if iopub: |
|
88 | 118 | self.iopub_channel.start() |
|
119 | for method in self.iopub_channel.proxy_methods: | |
|
120 | setattr(self, method, getattr(self.iopub_channel, method)) | |
|
89 | 121 | if stdin: |
|
90 | 122 | self.stdin_channel.start() |
|
123 | for method in self.stdin_channel.proxy_methods: | |
|
124 | setattr(self, method, getattr(self.stdin_channel, method)) | |
|
91 | 125 | self.shell_channel.allow_stdin = True |
|
92 | 126 | else: |
|
93 | 127 | self.shell_channel.allow_stdin = False |
@@ -63,20 +63,15 def flush_channels(kc=None): | |||
|
63 | 63 | |
|
64 | 64 | def execute(code='', kc=None, **kwargs): |
|
65 | 65 | """wrapper for doing common steps for validating an execution request""" |
|
66 | if kc is None: | |
|
67 | kc = KC | |
|
68 | shell = kc.shell_channel | |
|
69 | sub = kc.iopub_channel | |
|
70 | ||
|
71 | msg_id = shell.execute(code=code, **kwargs) | |
|
72 | reply = shell.get_msg(timeout=2) | |
|
66 | msg_id = KC.execute(code=code, **kwargs) | |
|
67 | reply = KC.get_shell_msg(timeout=2) | |
|
73 | 68 | list(validate_message(reply, 'execute_reply', msg_id)) |
|
74 |
busy = |
|
|
69 | busy = KC.get_iopub_msg(timeout=2) | |
|
75 | 70 | list(validate_message(busy, 'status', msg_id)) |
|
76 | 71 | nt.assert_equal(busy['content']['execution_state'], 'busy') |
|
77 | 72 | |
|
78 | 73 | if not kwargs.get('silent'): |
|
79 |
pyin = |
|
|
74 | pyin = KC.get_iopub_msg(timeout=2) | |
|
80 | 75 | list(validate_message(pyin, 'pyin', msg_id)) |
|
81 | 76 | nt.assert_equal(pyin['content']['code'], code) |
|
82 | 77 | |
@@ -302,9 +297,8 def validate_message(msg, msg_type=None, parent=None): | |||
|
302 | 297 | def test_execute(): |
|
303 | 298 | flush_channels() |
|
304 | 299 | |
|
305 | shell = KC.shell_channel | |
|
306 | msg_id = shell.execute(code='x=1') | |
|
307 | reply = shell.get_msg(timeout=2) | |
|
300 | msg_id = KC.execute(code='x=1') | |
|
301 | reply = KC.get_shell_msg(timeout=2) | |
|
308 | 302 | for tst in validate_message(reply, 'execute_reply', msg_id): |
|
309 | 303 | yield tst |
|
310 | 304 | |
@@ -383,10 +377,8 def test_user_expressions(): | |||
|
383 | 377 | def test_oinfo(): |
|
384 | 378 | flush_channels() |
|
385 | 379 | |
|
386 | shell = KC.shell_channel | |
|
387 | ||
|
388 | msg_id = shell.object_info('a') | |
|
389 | reply = shell.get_msg(timeout=2) | |
|
380 | msg_id = KC.object_info('a') | |
|
381 | reply = KC.get_shell_msg(timeout=2) | |
|
390 | 382 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
391 | 383 | yield tst |
|
392 | 384 | |
@@ -395,12 +387,10 def test_oinfo(): | |||
|
395 | 387 | def test_oinfo_found(): |
|
396 | 388 | flush_channels() |
|
397 | 389 | |
|
398 | shell = KC.shell_channel | |
|
399 | ||
|
400 | 390 | msg_id, reply = execute(code='a=5') |
|
401 | 391 | |
|
402 |
msg_id = |
|
|
403 |
reply = |
|
|
392 | msg_id = KC.object_info('a') | |
|
393 | reply = KC.get_shell_msg(timeout=2) | |
|
404 | 394 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
405 | 395 | yield tst |
|
406 | 396 | content = reply['content'] |
@@ -413,12 +403,10 def test_oinfo_found(): | |||
|
413 | 403 | def test_oinfo_detail(): |
|
414 | 404 | flush_channels() |
|
415 | 405 | |
|
416 | shell = KC.shell_channel | |
|
417 | ||
|
418 | 406 | msg_id, reply = execute(code='ip=get_ipython()') |
|
419 | 407 | |
|
420 |
msg_id = |
|
|
421 |
reply = |
|
|
408 | msg_id = KC.object_info('ip.object_inspect', detail_level=2) | |
|
409 | reply = KC.get_shell_msg(timeout=2) | |
|
422 | 410 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
423 | 411 | yield tst |
|
424 | 412 | content = reply['content'] |
@@ -432,10 +420,8 def test_oinfo_detail(): | |||
|
432 | 420 | def test_oinfo_not_found(): |
|
433 | 421 | flush_channels() |
|
434 | 422 | |
|
435 | shell = KC.shell_channel | |
|
436 | ||
|
437 | msg_id = shell.object_info('dne') | |
|
438 | reply = shell.get_msg(timeout=2) | |
|
423 | msg_id = KC.object_info('dne') | |
|
424 | reply = KC.get_shell_msg(timeout=2) | |
|
439 | 425 | for tst in validate_message(reply, 'object_info_reply', msg_id): |
|
440 | 426 | yield tst |
|
441 | 427 | content = reply['content'] |
@@ -446,12 +432,10 def test_oinfo_not_found(): | |||
|
446 | 432 | def test_complete(): |
|
447 | 433 | flush_channels() |
|
448 | 434 | |
|
449 | shell = KC.shell_channel | |
|
450 | ||
|
451 | 435 | msg_id, reply = execute(code="alpha = albert = 5") |
|
452 | 436 | |
|
453 |
msg_id = |
|
|
454 |
reply = |
|
|
437 | msg_id = KC.complete('al', 'al', 2) | |
|
438 | reply = KC.get_shell_msg(timeout=2) | |
|
455 | 439 | for tst in validate_message(reply, 'complete_reply', msg_id): |
|
456 | 440 | yield tst |
|
457 | 441 | matches = reply['content']['matches'] |
@@ -463,10 +447,8 def test_complete(): | |||
|
463 | 447 | def test_kernel_info_request(): |
|
464 | 448 | flush_channels() |
|
465 | 449 | |
|
466 | shell = KC.shell_channel | |
|
467 | ||
|
468 | msg_id = shell.kernel_info() | |
|
469 | reply = shell.get_msg(timeout=2) | |
|
450 | msg_id = KC.kernel_info() | |
|
451 | reply = KC.get_shell_msg(timeout=2) | |
|
470 | 452 | for tst in validate_message(reply, 'kernel_info_reply', msg_id): |
|
471 | 453 | yield tst |
|
472 | 454 |
@@ -106,22 +106,20 def test_embed_kernel_basic(): | |||
|
106 | 106 | ]) |
|
107 | 107 | |
|
108 | 108 | with setup_kernel(cmd) as client: |
|
109 | shell = client.shell_channel | |
|
110 | ||
|
111 | 109 | # oinfo a (int) |
|
112 |
msg_id = |
|
|
113 |
msg = |
|
|
110 | msg_id = client.object_info('a') | |
|
111 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
114 | 112 | content = msg['content'] |
|
115 | 113 | nt.assert_true(content['found']) |
|
116 | 114 | |
|
117 |
msg_id = |
|
|
118 |
msg = |
|
|
115 | msg_id = client.execute("c=a*2") | |
|
116 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
119 | 117 | content = msg['content'] |
|
120 | 118 | nt.assert_equal(content['status'], u'ok') |
|
121 | 119 | |
|
122 | 120 | # oinfo c (should be 10) |
|
123 |
msg_id = |
|
|
124 |
msg = |
|
|
121 | msg_id = client.object_info('c') | |
|
122 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
125 | 123 | content = msg['content'] |
|
126 | 124 | nt.assert_true(content['found']) |
|
127 | 125 | nt.assert_equal(content['string_form'], u'10') |
@@ -139,25 +137,23 def test_embed_kernel_namespace(): | |||
|
139 | 137 | ]) |
|
140 | 138 | |
|
141 | 139 | with setup_kernel(cmd) as client: |
|
142 | shell = client.shell_channel | |
|
143 | ||
|
144 | 140 | # oinfo a (int) |
|
145 |
msg_id = |
|
|
146 |
msg = |
|
|
141 | msg_id = client.object_info('a') | |
|
142 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
147 | 143 | content = msg['content'] |
|
148 | 144 | nt.assert_true(content['found']) |
|
149 | 145 | nt.assert_equal(content['string_form'], u'5') |
|
150 | 146 | |
|
151 | 147 | # oinfo b (str) |
|
152 |
msg_id = |
|
|
153 |
msg = |
|
|
148 | msg_id = client.object_info('b') | |
|
149 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
154 | 150 | content = msg['content'] |
|
155 | 151 | nt.assert_true(content['found']) |
|
156 | 152 | nt.assert_equal(content['string_form'], u'hi there') |
|
157 | 153 | |
|
158 | 154 | # oinfo c (undefined) |
|
159 |
msg_id = |
|
|
160 |
msg = |
|
|
155 | msg_id = client.object_info('c') | |
|
156 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
161 | 157 | content = msg['content'] |
|
162 | 158 | nt.assert_false(content['found']) |
|
163 | 159 | |
@@ -177,17 +173,16 def test_embed_kernel_reentrant(): | |||
|
177 | 173 | ]) |
|
178 | 174 | |
|
179 | 175 | with setup_kernel(cmd) as client: |
|
180 | shell = client.shell_channel | |
|
181 | 176 | for i in range(5): |
|
182 |
msg_id = |
|
|
183 |
msg = |
|
|
177 | msg_id = client.object_info('count') | |
|
178 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
184 | 179 | content = msg['content'] |
|
185 | 180 | nt.assert_true(content['found']) |
|
186 | 181 | nt.assert_equal(content['string_form'], unicode(i)) |
|
187 | 182 | |
|
188 | 183 | # exit from embed_kernel |
|
189 |
|
|
|
190 |
msg = |
|
|
184 | client.execute("get_ipython().exit_now = True") | |
|
185 | msg = client.get_shell_msg(block=True, timeout=2) | |
|
191 | 186 | time.sleep(0.2) |
|
192 | 187 | |
|
193 | 188 |
General Comments 0
You need to be logged in to leave comments.
Login now