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