##// END OF EJS Templates
* Added 'req_port' option to 'launch_kernel' and the kernel entry point....
epatters -
Show More
@@ -174,7 +174,7 b' class FrontendWidget(HistoryConsoleWidget):'
174 xreq.complete_reply.disconnect(self._handle_complete_reply)
174 xreq.complete_reply.disconnect(self._handle_complete_reply)
175 xreq.object_info_reply.disconnect(self._handle_object_info_reply)
175 xreq.object_info_reply.disconnect(self._handle_object_info_reply)
176
176
177 # Handle the case where the old kernel manager is still channels.
177 # Handle the case where the old kernel manager is still listening.
178 if self._kernel_manager.channels_running:
178 if self._kernel_manager.channels_running:
179 self._stopped_channels()
179 self._stopped_channels()
180
180
@@ -11,7 +11,6 b' from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \\'
11 from util import MetaQObjectHasTraits
11 from util import MetaQObjectHasTraits
12
12
13
13
14
15 class QtSubSocketChannel(SubSocketChannel, QtCore.QObject):
14 class QtSubSocketChannel(SubSocketChannel, QtCore.QObject):
16
15
17 # Emitted when any message is received.
16 # Emitted when any message is received.
@@ -18,8 +18,5 b' class MetaQObjectHasTraits(MetaQObject, MetaHasTraits):'
18 Using this metaclass allows a class to inherit from both HasTraits and
18 Using this metaclass allows a class to inherit from both HasTraits and
19 QObject. See QtKernelManager for an example.
19 QObject. See QtKernelManager for an example.
20 """
20 """
21
21 pass
22 def __init__(cls, name, bases, dct):
23 MetaQObject.__init__(cls, name, bases, dct)
24 MetaHasTraits.__init__(cls, name, bases, dct)
25
22
@@ -297,9 +297,11 b' def main():'
297 parser.add_argument('--ip', type=str, default='127.0.0.1',
297 parser.add_argument('--ip', type=str, default='127.0.0.1',
298 help='set the kernel\'s IP address [default: local]')
298 help='set the kernel\'s IP address [default: local]')
299 parser.add_argument('--xrep', type=int, metavar='PORT', default=0,
299 parser.add_argument('--xrep', type=int, metavar='PORT', default=0,
300 help='set the XREP Channel port [default: random]')
300 help='set the XREP channel port [default: random]')
301 parser.add_argument('--pub', type=int, metavar='PORT', default=0,
301 parser.add_argument('--pub', type=int, metavar='PORT', default=0,
302 help='set the PUB Channel port [default: random]')
302 help='set the PUB channel port [default: random]')
303 parser.add_argument('--req', type=int, metavar='PORT', default=0,
304 help='set the REQ channel port [default: random]')
303 parser.add_argument('--require-parent', action='store_true',
305 parser.add_argument('--require-parent', action='store_true',
304 help='ensure that this process dies with its parent')
306 help='ensure that this process dies with its parent')
305 namespace = parser.parse_args()
307 namespace = parser.parse_args()
@@ -339,7 +341,7 b' def main():'
339 # Start the kernel mainloop.
341 # Start the kernel mainloop.
340 kernel.start()
342 kernel.start()
341
343
342 def launch_kernel(xrep_port=0, pub_port=0, independent=False):
344 def launch_kernel(xrep_port=0, pub_port=0, req_port=0, independent=False):
343 """ Launches a localhost kernel, binding to the specified ports.
345 """ Launches a localhost kernel, binding to the specified ports.
344
346
345 Parameters
347 Parameters
@@ -348,7 +350,10 b' def launch_kernel(xrep_port=0, pub_port=0, independent=False):'
348 The port to use for XREP channel.
350 The port to use for XREP channel.
349
351
350 pub_port : int, optional
352 pub_port : int, optional
351 The port to use for the SUB Channel.
353 The port to use for the SUB channel.
354
355 req_port : int, optional
356 The port to use for the REQ (raw input) channel.
352
357
353 independent : bool, optional (default False)
358 independent : bool, optional (default False)
354 If set, the kernel process is guaranteed to survive if this process
359 If set, the kernel process is guaranteed to survive if this process
@@ -359,14 +364,15 b' def launch_kernel(xrep_port=0, pub_port=0, independent=False):'
359 Returns
364 Returns
360 -------
365 -------
361 A tuple of form:
366 A tuple of form:
362 (kernel_process [Popen], rep_port [int], sub_port [int])
367 (kernel_process, xrep_port, pub_port, req_port)
368 where kernel_process is a Popen object and the ports are integers.
363 """
369 """
364 import socket
370 import socket
365 from subprocess import Popen
371 from subprocess import Popen
366
372
367 # Find open ports as necessary.
373 # Find open ports as necessary.
368 ports = []
374 ports = []
369 ports_needed = int(xrep_port == 0) + int(pub_port == 0)
375 ports_needed = int(xrep_port <= 0) + int(pub_port <= 0) + int(req_port <= 0)
370 for i in xrange(ports_needed):
376 for i in xrange(ports_needed):
371 sock = socket.socket()
377 sock = socket.socket()
372 sock.bind(('', 0))
378 sock.bind(('', 0))
@@ -379,11 +385,13 b' def launch_kernel(xrep_port=0, pub_port=0, independent=False):'
379 xrep_port = ports.pop(0)
385 xrep_port = ports.pop(0)
380 if pub_port <= 0:
386 if pub_port <= 0:
381 pub_port = ports.pop(0)
387 pub_port = ports.pop(0)
388 if req_port <= 0:
389 req_port = ports.pop(0)
382
390
383 # Spawn a kernel.
391 # Spawn a kernel.
384 command = 'from IPython.zmq.kernel import main; main()'
392 command = 'from IPython.zmq.kernel import main; main()'
385 arguments = [ sys.executable, '-c', command,
393 arguments = [ sys.executable, '-c', command, '--xrep', str(xrep_port),
386 '--xrep', str(xrep_port), '--pub', str(pub_port) ]
394 '--pub', str(pub_port), '--req', str(req_port) ]
387
395
388 if independent:
396 if independent:
389 if sys.platform == 'win32':
397 if sys.platform == 'win32':
@@ -394,7 +402,7 b' def launch_kernel(xrep_port=0, pub_port=0, independent=False):'
394 else:
402 else:
395 proc = Popen(arguments + ['--require-parent'])
403 proc = Popen(arguments + ['--require-parent'])
396
404
397 return proc, xrep_port, pub_port
405 return proc, xrep_port, pub_port, req_port
398
406
399
407
400 if __name__ == '__main__':
408 if __name__ == '__main__':
@@ -74,7 +74,8 b' class ZmqSocketChannel(Thread):'
74 self.context = context
74 self.context = context
75 self.session = session
75 self.session = session
76 if address[1] == 0:
76 if address[1] == 0:
77 raise InvalidPortNumber('The port number for a channel cannot be 0.')
77 message = 'The port number for a channel cannot be 0.'
78 raise InvalidPortNumber(message)
78 self._address = address
79 self._address = address
79
80
80 def stop(self):
81 def stop(self):
@@ -345,7 +346,7 b' class RepSocketChannel(ZmqSocketChannel):'
345
346
346 def stop(self):
347 def stop(self):
347 self.ioloop.stop()
348 self.ioloop.stop()
348 super(SubSocketChannel, self).stop()
349 super(RepSocketChannel, self).stop()
349
350
350 def on_raw_input(self):
351 def on_raw_input(self):
351 pass
352 pass
General Comments 0
You need to be logged in to leave comments. Login now