##// END OF EJS Templates
Made is_alive a method of KernelManager and MultiKernelManager....
Brian E. Granger -
Show More
@@ -160,7 +160,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
160 160 self.km.shell_channel.get_msg()
161 161 # shell_channel.execute takes 'hidden', which is the inverse of store_hist
162 162 msg_id = self.km.shell_channel.execute(cell, not store_history)
163 while not self.km.shell_channel.msg_ready() and self.km.is_alive:
163 while not self.km.shell_channel.msg_ready() and self.km.is_alive():
164 164 try:
165 165 self.handle_stdin_request(timeout=0.05)
166 166 except Empty:
@@ -389,7 +389,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
389 389 # ask_exit callback.
390 390
391 391 while not self.exit_now:
392 if not self.km.is_alive:
392 if not self.km.is_alive():
393 393 # kernel died, prompt for action or exit
394 394 action = "restart" if self.km.has_kernel else "wait for restart"
395 395 ans = self.ask_yes_no("kernel died, %s ([y]/n)?" % action, default='y')
@@ -298,7 +298,6 b' class InProcessKernelManager(Configurable):'
298 298 def signal_kernel(self, signum):
299 299 raise NotImplementedError("Cannot signal in-process kernel.")
300 300
301 @property
302 301 def is_alive(self):
303 302 return True
304 303
@@ -985,7 +985,7 b' class KernelManager(Configurable):'
985 985 # most 1s, checking every 0.1s.
986 986 self.shell_channel.shutdown(restart=restart)
987 987 for i in range(10):
988 if self.is_alive:
988 if self.is_alive():
989 989 time.sleep(0.1)
990 990 else:
991 991 break
@@ -1100,7 +1100,6 b' class KernelManager(Configurable):'
1100 1100 else:
1101 1101 raise RuntimeError("Cannot signal kernel. No kernel is running!")
1102 1102
1103 @property
1104 1103 def is_alive(self):
1105 1104 """Is the kernel process still running?"""
1106 1105 if self.has_kernel:
@@ -220,7 +220,7 b' class KernelManagerABC(object):'
220 220 def signal_kernel(self, signum):
221 221 pass
222 222
223 @abc.abstractproperty
223 @abc.abstractmethod
224 224 def is_alive(self):
225 225 pass
226 226
@@ -154,6 +154,19 b' class MultiKernelManager(LoggingConfigurable):'
154 154 """
155 155 return self.get_kernel(kernel_id).restart_kernel()
156 156
157 def is_alive(self, kernel_id):
158 """Is the kernel alive.
159
160 This calls KernelManager.is_alive() which calls Popen.poll on the
161 actual kernel subprocess.
162
163 Parameters
164 ==========
165 kernel_id : uuid
166 The id of the kernel.
167 """
168 return self.get_kernel(kernel_id).is_alive()
169
157 170 def get_kernel(self, kernel_id):
158 171 """Get the single KernelManager object for a kernel by its uuid.
159 172
@@ -23,8 +23,10 b' class TestKernelManager(TestCase):'
23 23
24 24 def _run_lifecycle(self, km):
25 25 km.start_kernel(stdout=PIPE, stderr=PIPE)
26 self.assertTrue(km.is_alive())
26 27 km.start_channels(shell=True, iopub=False, stdin=False, hb=False)
27 28 km.restart_kernel()
29 self.assertTrue(km.is_alive())
28 30 # We need a delay here to give the restarting kernel a chance to
29 31 # restart. Otherwise, the interrupt will kill it, causing the test
30 32 # suite to hang. The reason it *hangs* is that the shutdown
@@ -25,10 +25,12 b' class TestKernelManager(TestCase):'
25 25
26 26 def _run_lifecycle(self, km):
27 27 kid = km.start_kernel(stdout=PIPE, stderr=PIPE)
28 self.assertTrue(km.is_alive(kid))
28 29 self.assertTrue(kid in km)
29 30 self.assertTrue(kid in km.list_kernel_ids())
30 31 self.assertEqual(len(km),1)
31 32 km.restart_kernel(kid)
33 self.assertTrue(km.is_alive(kid))
32 34 self.assertTrue(kid in km.list_kernel_ids())
33 35 # We need a delay here to give the restarting kernel a chance to
34 36 # restart. Otherwise, the interrupt will kill it, causing the test
General Comments 0
You need to be logged in to leave comments. Login now