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