##// END OF EJS Templates
Possible fix for GH-169
MinRK -
Show More
@@ -16,10 +16,10 b' from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget'
16 from IPython.frontend.qt.kernelmanager import QtKernelManager
16 from IPython.frontend.qt.kernelmanager import QtKernelManager
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Constants
19 # Network Constants
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 LOCALHOST = '127.0.0.1'
22 from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 # Classes
25 # Classes
@@ -45,7 +45,7 b' class MainWindow(QtGui.QMainWindow):'
45 self._app = app
45 self._app = app
46 self._frontend = frontend
46 self._frontend = frontend
47 self._existing = existing
47 self._existing = existing
48 if not existing:
48 if existing:
49 self._may_close = may_close
49 self._may_close = may_close
50 else:
50 else:
51 self._may_close = True
51 self._may_close = True
@@ -144,12 +144,16 b' def main():'
144 rep_address=(args.ip, args.rep),
144 rep_address=(args.ip, args.rep),
145 hb_address=(args.ip, args.hb))
145 hb_address=(args.ip, args.hb))
146 if not args.existing:
146 if not args.existing:
147 # if not args.ip in LOCAL_IPS+ALL_ALIAS:
148 # raise ValueError("Must bind a local ip, such as: %s"%LOCAL_IPS)
149
150 kwargs = dict(ip=args.ip)
147 if args.pure:
151 if args.pure:
148 kernel_manager.start_kernel(ipython=False)
152 kwargs['ipython']=False
149 elif args.pylab:
153 elif args.pylab:
150 kernel_manager.start_kernel(pylab=args.pylab)
154 kwargs['pylab']=args.pylab
151 else:
155
152 kernel_manager.start_kernel()
156 kernel_manager.start_kernel(**kwargs)
153 kernel_manager.start_channels()
157 kernel_manager.start_channels()
154
158
155 local_kernel = (not args.existing) or args.ip == LOCALHOST
159 local_kernel = (not args.existing) or args.ip == LOCALHOST
@@ -16,6 +16,7 b' import zmq'
16 from IPython.core.ultratb import FormattedTB
16 from IPython.core.ultratb import FormattedTB
17 from IPython.external.argparse import ArgumentParser
17 from IPython.external.argparse import ArgumentParser
18 from IPython.utils import io
18 from IPython.utils import io
19 from IPython.utils.localinterfaces import LOCALHOST
19 from displayhook import DisplayHook
20 from displayhook import DisplayHook
20 from heartbeat import Heartbeat
21 from heartbeat import Heartbeat
21 from iostream import OutStream
22 from iostream import OutStream
@@ -40,7 +41,7 b' def make_argument_parser():'
40 kernel entry points.
41 kernel entry points.
41 """
42 """
42 parser = ArgumentParser()
43 parser = ArgumentParser()
43 parser.add_argument('--ip', type=str, default='127.0.0.1',
44 parser.add_argument('--ip', type=str, default=LOCALHOST,
44 help='set the kernel\'s IP address [default: local]')
45 help='set the kernel\'s IP address [default: local]')
45 parser.add_argument('--xrep', type=int, metavar='PORT', default=0,
46 parser.add_argument('--xrep', type=int, metavar='PORT', default=0,
46 help='set the XREP channel port [default: random]')
47 help='set the XREP channel port [default: random]')
@@ -17,6 +17,7 b' import uuid'
17 import zmq
17 import zmq
18 import session
18 import session
19 import completer
19 import completer
20 from IPython.utils.localinterfaces import LOCALHOST
20
21
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 # Classes and functions
23 # Classes and functions
@@ -168,7 +169,7 b' class InteractiveClient(object):'
168 def main():
169 def main():
169 # Defaults
170 # Defaults
170 #ip = '192.168.2.109'
171 #ip = '192.168.2.109'
171 ip = '127.0.0.1'
172 ip = LOCALHOST
172 #ip = '99.146.222.252'
173 #ip = '99.146.222.252'
173 port_base = 5575
174 port_base = 5575
174 connection = ('tcp://%s' % ip) + ':%i'
175 connection = ('tcp://%s' % ip) + ':%i'
@@ -17,6 +17,8 b' from threading import Thread'
17
17
18 import zmq
18 import zmq
19
19
20 from IPython.utils.localinterfaces import LOCALHOST
21
20 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
21 # Code
23 # Code
22 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
@@ -25,7 +27,7 b' import zmq'
25 class Heartbeat(Thread):
27 class Heartbeat(Thread):
26 "A simple ping-pong style heartbeat that runs in a thread."
28 "A simple ping-pong style heartbeat that runs in a thread."
27
29
28 def __init__(self, context, addr=('127.0.0.1', 0)):
30 def __init__(self, context, addr=(LOCALHOST, 0)):
29 Thread.__init__(self)
31 Thread.__init__(self)
30 self.context = context
32 self.context = context
31 self.addr = addr
33 self.addr = addr
@@ -534,12 +534,15 b' class GTKKernel(Kernel):'
534 # Kernel main and launch functions
534 # Kernel main and launch functions
535 #-----------------------------------------------------------------------------
535 #-----------------------------------------------------------------------------
536
536
537 def launch_kernel(xrep_port=0, pub_port=0, req_port=0, hb_port=0,
537 def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,
538 independent=False, pylab=False):
538 independent=False, pylab=False):
539 """Launches a localhost kernel, binding to the specified ports.
539 """Launches a localhost kernel, binding to the specified ports.
540
540
541 Parameters
541 Parameters
542 ----------
542 ----------
543 ip : str, optional
544 The ip address the kernel will bind to.
545
543 xrep_port : int, optional
546 xrep_port : int, optional
544 The port to use for XREP channel.
547 The port to use for XREP channel.
545
548
@@ -574,6 +577,10 b' def launch_kernel(xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
574 extra_arguments.append('--pylab')
577 extra_arguments.append('--pylab')
575 if isinstance(pylab, basestring):
578 if isinstance(pylab, basestring):
576 extra_arguments.append(pylab)
579 extra_arguments.append(pylab)
580 if ip is not None:
581 extra_arguments.append('--ip')
582 if isinstance(ip, basestring):
583 extra_arguments.append(ip)
577 return base_launch_kernel('from IPython.zmq.ipkernel import main; main()',
584 return base_launch_kernel('from IPython.zmq.ipkernel import main; main()',
578 xrep_port, pub_port, req_port, hb_port,
585 xrep_port, pub_port, req_port, hb_port,
579 independent, extra_arguments)
586 independent, extra_arguments)
@@ -31,6 +31,7 b' from zmq.eventloop import ioloop'
31
31
32 # Local imports.
32 # Local imports.
33 from IPython.utils import io
33 from IPython.utils import io
34 from IPython.utils.localinterfaces import LOCALHOST, LOCAL_IPS
34 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress
35 from IPython.utils.traitlets import HasTraits, Any, Instance, Type, TCPAddress
35 from session import Session
36 from session import Session
36
37
@@ -38,8 +39,6 b' from session import Session'
38 # Constants and exceptions
39 # Constants and exceptions
39 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
40
41
41 LOCALHOST = '127.0.0.1'
42
43 class InvalidPortNumber(Exception):
42 class InvalidPortNumber(Exception):
44 pass
43 pass
45
44
@@ -724,24 +723,26 b' class KernelManager(HasTraits):'
724 """
723 """
725 xreq, sub, rep, hb = self.xreq_address, self.sub_address, \
724 xreq, sub, rep, hb = self.xreq_address, self.sub_address, \
726 self.rep_address, self.hb_address
725 self.rep_address, self.hb_address
727 if xreq[0] != LOCALHOST or sub[0] != LOCALHOST or \
726 if xreq[0] not in LOCAL_IPS or sub[0] not in LOCAL_IPS or \
728 rep[0] != LOCALHOST or hb[0] != LOCALHOST:
727 rep[0] not in LOCAL_IPS or hb[0] not in LOCAL_IPS:
729 raise RuntimeError("Can only launch a kernel on localhost."
728 raise RuntimeError("Can only launch a kernel on a local interface. "
730 "Make sure that the '*_address' attributes are "
729 "Make sure that the '*_address' attributes are "
731 "configured properly.")
730 "configured properly. "
732
731 "Currently valid addresses are: %s"%LOCAL_IPS
732 )
733
733 self._launch_args = kw.copy()
734 self._launch_args = kw.copy()
734 if kw.pop('ipython', True):
735 if kw.pop('ipython', True):
735 from ipkernel import launch_kernel
736 from ipkernel import launch_kernel
736 else:
737 else:
737 from pykernel import launch_kernel
738 from pykernel import launch_kernel
738 self.kernel, xrep, pub, req, hb = launch_kernel(
739 self.kernel, xrep, pub, req, _hb = launch_kernel(
739 xrep_port=xreq[1], pub_port=sub[1],
740 xrep_port=xreq[1], pub_port=sub[1],
740 req_port=rep[1], hb_port=hb[1], **kw)
741 req_port=rep[1], hb_port=hb[1], **kw)
741 self.xreq_address = (LOCALHOST, xrep)
742 self.xreq_address = (xreq[0], xrep)
742 self.sub_address = (LOCALHOST, pub)
743 self.sub_address = (sub[0], pub)
743 self.rep_address = (LOCALHOST, req)
744 self.rep_address = (rep[0], req)
744 self.hb_address = (LOCALHOST, hb)
745 self.hb_address = (hb[0], _hb)
745
746
746 def shutdown_kernel(self, restart=False):
747 def shutdown_kernel(self, restart=False):
747 """ Attempts to the stop the kernel process cleanly. If the kernel
748 """ Attempts to the stop the kernel process cleanly. If the kernel
@@ -256,12 +256,15 b' class Kernel(HasTraits):'
256 # Kernel main and launch functions
256 # Kernel main and launch functions
257 #-----------------------------------------------------------------------------
257 #-----------------------------------------------------------------------------
258
258
259 def launch_kernel(xrep_port=0, pub_port=0, req_port=0, hb_port=0,
259 def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,
260 independent=False):
260 independent=False):
261 """ Launches a localhost kernel, binding to the specified ports.
261 """ Launches a localhost kernel, binding to the specified ports.
262
262
263 Parameters
263 Parameters
264 ----------
264 ----------
265 ip : str, optional
266 The ip address the kernel will bind to.
267
265 xrep_port : int, optional
268 xrep_port : int, optional
266 The port to use for XREP channel.
269 The port to use for XREP channel.
267
270
@@ -286,9 +289,15 b' def launch_kernel(xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
286 (kernel_process, xrep_port, pub_port, req_port)
289 (kernel_process, xrep_port, pub_port, req_port)
287 where kernel_process is a Popen object and the ports are integers.
290 where kernel_process is a Popen object and the ports are integers.
288 """
291 """
292 extra_arguments = []
293 if ip is not None:
294 extra_arguments.append('--ip')
295 if isinstance(ip, basestring):
296 extra_arguments.append(ip)
297
289 return base_launch_kernel('from IPython.zmq.pykernel import main; main()',
298 return base_launch_kernel('from IPython.zmq.pykernel import main; main()',
290 xrep_port, pub_port, req_port, hb_port,
299 xrep_port, pub_port, req_port, hb_port,
291 independent)
300 independent, extra_arguments=extra_arguments)
292
301
293 main = make_default_main(Kernel)
302 main = make_default_main(Kernel)
294
303
General Comments 0
You need to be logged in to leave comments. Login now