##// END OF EJS Templates
BUG: Block until kernel termination after sending a kill signal.
epatters -
Show More
@@ -812,8 +812,9 b' class KernelManager(HasTraits):'
812 self.kernel = launch_kernel(fname=self.connection_file, **kw)
812 self.kernel = launch_kernel(fname=self.connection_file, **kw)
813
813
814 def shutdown_kernel(self, restart=False):
814 def shutdown_kernel(self, restart=False):
815 """ Attempts to the stop the kernel process cleanly. If the kernel
815 """ Attempts to the stop the kernel process cleanly.
816 cannot be stopped, it is killed, if possible.
816
817 If the kernel cannot be stopped and the kernel is local, it is killed.
817 """
818 """
818 # FIXME: Shutdown does not work on Windows due to ZMQ errors!
819 # FIXME: Shutdown does not work on Windows due to ZMQ errors!
819 if sys.platform == 'win32':
820 if sys.platform == 'win32':
@@ -894,13 +895,17 b' class KernelManager(HasTraits):'
894 return self.kernel is not None
895 return self.kernel is not None
895
896
896 def kill_kernel(self):
897 def kill_kernel(self):
897 """ Kill the running kernel. """
898 """ Kill the running kernel.
899
900 This method blocks until the kernel process has terminated.
901 """
898 if self.has_kernel:
902 if self.has_kernel:
899 # Pause the heart beat channel if it exists.
903 # Pause the heart beat channel if it exists.
900 if self._hb_channel is not None:
904 if self._hb_channel is not None:
901 self._hb_channel.pause()
905 self._hb_channel.pause()
902
906
903 # Attempt to kill the kernel.
907 # Signal the kernel to terminate (sends SIGKILL on Unix and calls
908 # TerminateProcess() on Win32).
904 try:
909 try:
905 self.kernel.kill()
910 self.kernel.kill()
906 except OSError as e:
911 except OSError as e:
@@ -915,13 +920,18 b' class KernelManager(HasTraits):'
915 from errno import ESRCH
920 from errno import ESRCH
916 if e.errno != ESRCH:
921 if e.errno != ESRCH:
917 raise
922 raise
923
924 # Block until the kernel terminates.
925 self.kernel.wait()
918 self.kernel = None
926 self.kernel = None
919 else:
927 else:
920 raise RuntimeError("Cannot kill kernel. No kernel is running!")
928 raise RuntimeError("Cannot kill kernel. No kernel is running!")
921
929
922 def interrupt_kernel(self):
930 def interrupt_kernel(self):
923 """ Interrupts the kernel. Unlike ``signal_kernel``, this operation is
931 """ Interrupts the kernel.
924 well supported on all platforms.
932
933 Unlike ``signal_kernel``, this operation is well supported on all
934 platforms.
925 """
935 """
926 if self.has_kernel:
936 if self.has_kernel:
927 if sys.platform == 'win32':
937 if sys.platform == 'win32':
@@ -933,8 +943,10 b' class KernelManager(HasTraits):'
933 raise RuntimeError("Cannot interrupt kernel. No kernel is running!")
943 raise RuntimeError("Cannot interrupt kernel. No kernel is running!")
934
944
935 def signal_kernel(self, signum):
945 def signal_kernel(self, signum):
936 """ Sends a signal to the kernel. Note that since only SIGTERM is
946 """ Sends a signal to the kernel.
937 supported on Windows, this function is only useful on Unix systems.
947
948 Note that since only SIGTERM is supported on Windows, this function is
949 only useful on Unix systems.
938 """
950 """
939 if self.has_kernel:
951 if self.has_kernel:
940 self.kernel.send_signal(signum)
952 self.kernel.send_signal(signum)
General Comments 0
You need to be logged in to leave comments. Login now