##// END OF EJS Templates
KernelManager has port traits instead of multiple ip/port pairs...
MinRK -
Show More
@@ -371,12 +371,12 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
371 signal.signal(signal.SIGINT, signal.SIG_DFL)
371 signal.signal(signal.SIGINT, signal.SIG_DFL)
372
372
373 # Create a KernelManager and start a kernel.
373 # Create a KernelManager and start a kernel.
374 self.kernel_manager = QtKernelManager(
374 self.kernel_manager = QtKernelManager(ip=self.ip,
375 shell_address=(self.ip, self.shell_port),
375 shell_port=self.shell_port,
376 sub_address=(self.ip, self.iopub_port),
376 sub_port=self.iopub_port,
377 stdin_address=(self.ip, self.stdin_port),
377 stdin_port=self.stdin_port,
378 hb_address=(self.ip, self.hb_port),
378 hb_port=self.hb_port,
379 config=self.config
379 config=self.config,
380 )
380 )
381 # start the kernel
381 # start the kernel
382 if not self.existing:
382 if not self.existing:
@@ -16,7 +16,6 b' TODO'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # Standard library imports.
18 # Standard library imports.
19 import atexit
20 import errno
19 import errno
21 from Queue import Queue, Empty
20 from Queue import Queue, Empty
22 from subprocess import Popen
21 from subprocess import Popen
@@ -24,7 +23,6 b' import signal'
24 import sys
23 import sys
25 from threading import Thread
24 from threading import Thread
26 import time
25 import time
27 import logging
28
26
29 # System library imports.
27 # System library imports.
30 import zmq
28 import zmq
@@ -33,10 +31,9 b' from zmq.eventloop import ioloop'
33
31
34 # Local imports.
32 # Local imports.
35 from IPython.config.loader import Config
33 from IPython.config.loader import Config
36 from IPython.utils import io
37 from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS
34 from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS
38 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress
35 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, Unicode, Int
39 from session import Session, Message
36 from session import Session
40
37
41 #-----------------------------------------------------------------------------
38 #-----------------------------------------------------------------------------
42 # Constants and exceptions
39 # Constants and exceptions
@@ -705,10 +702,11 b' class KernelManager(HasTraits):'
705 kernel = Instance(Popen)
702 kernel = Instance(Popen)
706
703
707 # The addresses for the communication channels.
704 # The addresses for the communication channels.
708 shell_address = TCPAddress((LOCALHOST, 0))
705 ip = Unicode(LOCALHOST)
709 sub_address = TCPAddress((LOCALHOST, 0))
706 shell_port = Int(0)
710 stdin_address = TCPAddress((LOCALHOST, 0))
707 sub_port = Int(0)
711 hb_address = TCPAddress((LOCALHOST, 0))
708 stdin_port = Int(0)
709 hb_port = Int(0)
712
710
713 # The classes to use for the various channels.
711 # The classes to use for the various channels.
714 shell_channel_class = Type(ShellSocketChannel)
712 shell_channel_class = Type(ShellSocketChannel)
@@ -795,10 +793,7 b' class KernelManager(HasTraits):'
795 **kw : optional
793 **kw : optional
796 See respective options for IPython and Python kernels.
794 See respective options for IPython and Python kernels.
797 """
795 """
798 shell, sub, stdin, hb = self.shell_address, self.sub_address, \
796 if self.ip not in LOCAL_IPS:
799 self.stdin_address, self.hb_address
800 if shell[0] not in LOCAL_IPS or sub[0] not in LOCAL_IPS or \
801 stdin[0] not in LOCAL_IPS or hb[0] not in LOCAL_IPS:
802 raise RuntimeError("Can only launch a kernel on a local interface. "
797 raise RuntimeError("Can only launch a kernel on a local interface. "
803 "Make sure that the '*_address' attributes are "
798 "Make sure that the '*_address' attributes are "
804 "configured properly. "
799 "configured properly. "
@@ -812,13 +807,13 b' class KernelManager(HasTraits):'
812 from ipkernel import launch_kernel
807 from ipkernel import launch_kernel
813 else:
808 else:
814 from pykernel import launch_kernel
809 from pykernel import launch_kernel
815 self.kernel, xrep, pub, req, _hb = launch_kernel(
810 self.kernel, shell, sub, stdin, hb = launch_kernel(
816 shell_port=shell[1], iopub_port=sub[1],
811 shell_port=self.shell_port, iopub_port=self.sub_port,
817 stdin_port=stdin[1], hb_port=hb[1], **kw)
812 stdin_port=self.stdin_port, hb_port=self.hb_port, **kw)
818 self.shell_address = (shell[0], xrep)
813 self.shell_port = shell
819 self.sub_address = (sub[0], pub)
814 self.sub_port = sub
820 self.stdin_address = (stdin[0], req)
815 self.stdin_port = stdin
821 self.hb_address = (hb[0], _hb)
816 self.hb_port = hb
822
817
823 def shutdown_kernel(self, restart=False):
818 def shutdown_kernel(self, restart=False):
824 """ Attempts to the stop the kernel process cleanly. If the kernel
819 """ Attempts to the stop the kernel process cleanly. If the kernel
@@ -967,7 +962,7 b' class KernelManager(HasTraits):'
967 if self._shell_channel is None:
962 if self._shell_channel is None:
968 self._shell_channel = self.shell_channel_class(self.context,
963 self._shell_channel = self.shell_channel_class(self.context,
969 self.session,
964 self.session,
970 self.shell_address)
965 (self.ip, self.shell_port))
971 return self._shell_channel
966 return self._shell_channel
972
967
973 @property
968 @property
@@ -976,7 +971,7 b' class KernelManager(HasTraits):'
976 if self._sub_channel is None:
971 if self._sub_channel is None:
977 self._sub_channel = self.sub_channel_class(self.context,
972 self._sub_channel = self.sub_channel_class(self.context,
978 self.session,
973 self.session,
979 self.sub_address)
974 (self.ip, self.sub_port))
980 return self._sub_channel
975 return self._sub_channel
981
976
982 @property
977 @property
@@ -985,7 +980,7 b' class KernelManager(HasTraits):'
985 if self._stdin_channel is None:
980 if self._stdin_channel is None:
986 self._stdin_channel = self.stdin_channel_class(self.context,
981 self._stdin_channel = self.stdin_channel_class(self.context,
987 self.session,
982 self.session,
988 self.stdin_address)
983 (self.ip, self.stdin_port))
989 return self._stdin_channel
984 return self._stdin_channel
990
985
991 @property
986 @property
@@ -995,5 +990,5 b' class KernelManager(HasTraits):'
995 if self._hb_channel is None:
990 if self._hb_channel is None:
996 self._hb_channel = self.hb_channel_class(self.context,
991 self._hb_channel = self.hb_channel_class(self.context,
997 self.session,
992 self.session,
998 self.hb_address)
993 (self.ip, self.hb_port))
999 return self._hb_channel
994 return self._hb_channel
General Comments 0
You need to be logged in to leave comments. Login now