Show More
@@ -13,13 +13,15 class BaseFrontendMixin(object): | |||||
13 | # 'BaseFrontendMixin' concrete interface |
|
13 | # 'BaseFrontendMixin' concrete interface | |
14 | #--------------------------------------------------------------------------- |
|
14 | #--------------------------------------------------------------------------- | |
15 | _kernel_client = None |
|
15 | _kernel_client = None | |
|
16 | _kernel_manager = None | |||
16 |
|
17 | |||
17 | def _get_kernel_client(self): |
|
18 | @property | |
18 | """Returns the current kernel client. |
|
19 | def kernel_client(self): | |
19 | """ |
|
20 | """Returns the current kernel client.""" | |
20 | return self._kernel_client |
|
21 | return self._kernel_client | |
21 |
|
22 | |||
22 | def _set_kernel_client(self, kernel_client): |
|
23 | @kernel_client.setter | |
|
24 | def kernel_client(self, kernel_client): | |||
23 | """Disconnect from the current kernel client (if any) and set a new |
|
25 | """Disconnect from the current kernel client (if any) and set a new | |
24 | kernel client. |
|
26 | kernel client. | |
25 | """ |
|
27 | """ | |
@@ -53,6 +55,7 class BaseFrontendMixin(object): | |||||
53 | kernel_client.iopub_channel.message_received.connect(self._dispatch) |
|
55 | kernel_client.iopub_channel.message_received.connect(self._dispatch) | |
54 | kernel_client.shell_channel.message_received.connect(self._dispatch) |
|
56 | kernel_client.shell_channel.message_received.connect(self._dispatch) | |
55 | kernel_client.stdin_channel.message_received.connect(self._dispatch) |
|
57 | kernel_client.stdin_channel.message_received.connect(self._dispatch) | |
|
58 | # hb_channel | |||
56 | kernel_client.hb_channel.kernel_died.connect(self._handle_kernel_died) |
|
59 | kernel_client.hb_channel.kernel_died.connect(self._handle_kernel_died) | |
57 |
|
60 | |||
58 | # Handle the case where the kernel client started channels before |
|
61 | # Handle the case where the kernel client started channels before | |
@@ -60,7 +63,22 class BaseFrontendMixin(object): | |||||
60 | if kernel_client.channels_running: |
|
63 | if kernel_client.channels_running: | |
61 | self._started_channels() |
|
64 | self._started_channels() | |
62 |
|
65 | |||
63 | kernel_client = property(_get_kernel_client, _set_kernel_client) |
|
66 | @property | |
|
67 | def kernel_manager(self): | |||
|
68 | """The kernel manager, if any""" | |||
|
69 | return self._kernel_manager | |||
|
70 | ||||
|
71 | @kernel_manager.setter | |||
|
72 | def kernel_manager(self, kernel_manager): | |||
|
73 | old_man = self._kernel_manager | |||
|
74 | if old_man is not None: | |||
|
75 | old_man.kernel_restarted.disconnect(self._handle_kernel_restarted) | |||
|
76 | ||||
|
77 | self._kernel_manager = kernel_manager | |||
|
78 | if kernel_manager is None: | |||
|
79 | return | |||
|
80 | ||||
|
81 | kernel_manager.kernel_restarted.connect(self._handle_kernel_restarted) | |||
64 |
|
82 | |||
65 | #--------------------------------------------------------------------------- |
|
83 | #--------------------------------------------------------------------------- | |
66 | # 'BaseFrontendMixin' abstract interface |
|
84 | # 'BaseFrontendMixin' abstract interface | |
@@ -70,8 +88,9 class BaseFrontendMixin(object): | |||||
70 | """ This is called when the ``kernel_died`` signal is emitted. |
|
88 | """ This is called when the ``kernel_died`` signal is emitted. | |
71 |
|
89 | |||
72 | This method is called when the kernel heartbeat has not been |
|
90 | This method is called when the kernel heartbeat has not been | |
73 |
active for a certain amount of time. |
|
91 | active for a certain amount of time. | |
74 | give the user the option of restarting the kernel. |
|
92 | This is a strictly passive notification - | |
|
93 | the kernel is likely being restarted by its KernelManager. | |||
75 |
|
94 | |||
76 | Parameters |
|
95 | Parameters | |
77 | ---------- |
|
96 | ---------- | |
@@ -79,6 +98,17 class BaseFrontendMixin(object): | |||||
79 | The time since the heartbeat was last received. |
|
98 | The time since the heartbeat was last received. | |
80 | """ |
|
99 | """ | |
81 |
|
100 | |||
|
101 | def _handle_kernel_restarted(self): | |||
|
102 | """ This is called when the ``kernel_restarted`` signal is emitted. | |||
|
103 | ||||
|
104 | This method is called when the kernel has been restarted by the | |||
|
105 | autorestart mechanism. | |||
|
106 | ||||
|
107 | Parameters | |||
|
108 | ---------- | |||
|
109 | since_last_heartbeat : float | |||
|
110 | The time since the heartbeat was last received. | |||
|
111 | """ | |||
82 | def _started_kernel(self): |
|
112 | def _started_kernel(self): | |
83 | """Called when the KernelManager starts (or restarts) the kernel subprocess. |
|
113 | """Called when the KernelManager starts (or restarts) the kernel subprocess. | |
84 | Channels may or may not be running at this point. |
|
114 | Channels may or may not be running at this point. |
General Comments 0
You need to be logged in to leave comments.
Login now