Show More
@@ -1,39 +1,38 b'' | |||||
1 | """Implements a fully blocking kernel client. |
|
1 | """Implements a fully blocking kernel client. | |
2 |
|
2 | |||
3 | Useful for test suites and blocking terminal interfaces. |
|
3 | Useful for test suites and blocking terminal interfaces. | |
4 | """ |
|
4 | """ | |
5 | # Copyright (c) IPython Development Team. |
|
5 | # Copyright (c) IPython Development Team. | |
6 | # Distributed under the terms of the Modified BSD License. |
|
6 | # Distributed under the terms of the Modified BSD License. | |
7 |
|
7 | |||
8 | try: |
|
8 | try: | |
9 | from queue import Empty # Python 3 |
|
9 | from queue import Empty # Python 3 | |
10 | except ImportError: |
|
10 | except ImportError: | |
11 | from Queue import Empty # Python 2 |
|
11 | from Queue import Empty # Python 2 | |
12 |
|
12 | |||
13 | from IPython.utils.traitlets import Type |
|
13 | from IPython.utils.traitlets import Type | |
14 | from IPython.kernel.channels import HBChannel |
|
14 | from IPython.kernel.channels import HBChannel | |
15 | from IPython.kernel.client import KernelClient |
|
15 | from IPython.kernel.client import KernelClient | |
16 | from .channels import ZMQSocketChannel |
|
16 | from .channels import ZMQSocketChannel | |
17 |
|
17 | |||
18 | class BlockingKernelClient(KernelClient): |
|
18 | class BlockingKernelClient(KernelClient): | |
19 | def wait_for_ready(self): |
|
19 | def wait_for_ready(self): | |
20 | # Wait for kernel info reply on shell channel |
|
20 | # Wait for kernel info reply on shell channel | |
21 | while True: |
|
21 | while True: | |
22 | msg = self.shell_channel.get_msg(block=True) |
|
22 | msg = self.shell_channel.get_msg(block=True) | |
23 | if msg['msg_type'] == 'kernel_info_reply': |
|
23 | if msg['msg_type'] == 'kernel_info_reply': | |
24 | self._handle_kernel_info_reply(msg) |
|
24 | self._handle_kernel_info_reply(msg) | |
25 | break |
|
25 | break | |
26 |
|
26 | |||
27 | # Flush IOPub channel |
|
27 | # Flush IOPub channel | |
28 | while True: |
|
28 | while True: | |
29 | try: |
|
29 | try: | |
30 | msg = self.iopub_channel.get_msg(block=True, timeout=0.2) |
|
30 | msg = self.iopub_channel.get_msg(block=True, timeout=0.2) | |
31 | print(msg['msg_type']) |
|
|||
32 | except Empty: |
|
31 | except Empty: | |
33 | break |
|
32 | break | |
34 |
|
33 | |||
35 | # The classes to use for the various channels |
|
34 | # The classes to use for the various channels | |
36 | shell_channel_class = Type(ZMQSocketChannel) |
|
35 | shell_channel_class = Type(ZMQSocketChannel) | |
37 | iopub_channel_class = Type(ZMQSocketChannel) |
|
36 | iopub_channel_class = Type(ZMQSocketChannel) | |
38 | stdin_channel_class = Type(ZMQSocketChannel) |
|
37 | stdin_channel_class = Type(ZMQSocketChannel) | |
39 | hb_channel_class = Type(HBChannel) |
|
38 | hb_channel_class = Type(HBChannel) |
General Comments 0
You need to be logged in to leave comments.
Login now