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