Skip to content
This repository

add `ipython kernel` for starting just a kernel #687

Merged
merged 3 commits into from over 2 years ago

2 participants

Min RK Fernando Perez
Min RK
Owner

Also fixed an issue that the --existing... message would be inaccurate if the heartbeat port is unspecified.

added some commits August 08, 2011
Min RK specify heartbeat port at construction, not in run
when port=0, the heartbeat port would be unknown until the heartbeat
started, making the '--existing…' message inaccurate.
79472ea
Min RK add 'ipython kernel' entry point
For starting a kernel without a frontend.
b7add9e
Fernando Perez
Owner

Awesome, thanks! Min, before merging, could you update the examples I wrote in examples/lib to remove the hardcoding of the hb port, since you've now fixed that? Then we can merge this and point people who are asking about all this on-list to do a master pull.

Great to have this!

Min RK
Owner

fixed.

Fernando Perez fperez merged commit 4e1a76c into from August 08, 2011
Fernando Perez fperez closed this August 08, 2011
Fernando Perez
Owner

Thanks! Merged and pushed. This is excellent to have...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Aug 08, 2011
Min RK specify heartbeat port at construction, not in run
when port=0, the heartbeat port would be unknown until the heartbeat
started, making the '--existing…' message inaccurate.
79472ea
Min RK add 'ipython kernel' entry point
For starting a kernel without a frontend.
b7add9e
Min RK remove hardcoded hb port from internal example
The Related bug has been fixed.
4e1a76c
This page is out of date. Refresh to see the latest.
6  IPython/frontend/terminal/ipapp.py
@@ -205,7 +205,11 @@ def _classes_default(self):
205 205
             """Launch the IPython Qt Console."""
206 206
         ),
207 207
         profile = ("IPython.core.profileapp.ProfileApp",
208  
-            "Create and manage IPython profiles.")
  208
+            "Create and manage IPython profiles."
  209
+        ),
  210
+        kernel = ("IPython.zmq.ipkernel.IPKernelApp",
  211
+            "Start a kernel without an attached frontend."
  212
+        ),
209 213
     ))
210 214
     
211 215
     # *do* autocreate requested profile, but don't create the config file.
12  IPython/zmq/heartbeat.py
@@ -12,6 +12,7 @@
12 12
 # Imports
13 13
 #-----------------------------------------------------------------------------
14 14
 
  15
+import socket
15 16
 import sys
16 17
 from threading import Thread
17 18
 
@@ -33,13 +34,16 @@ def __init__(self, context, addr=(LOCALHOST, 0)):
33 34
         self.addr = addr
34 35
         self.ip = addr[0]
35 36
         self.port = addr[1]
  37
+        if self.port == 0:
  38
+            s = socket.socket()
  39
+            s.bind(self.addr)
  40
+            self.port = s.getsockname()[1]
  41
+            s.close()
  42
+            self.addr = (self.ip, self.port)
36 43
         self.daemon = True
37 44
 
38 45
     def run(self):
39 46
         self.socket = self.context.socket(zmq.REP)
40  
-        if self.port == 0:
41  
-            self.port = self.socket.bind_to_random_port('tcp://%s' % self.ip)
42  
-        else:
43  
-            self.socket.bind('tcp://%s:%i' % self.addr)
  47
+        self.socket.bind('tcp://%s:%i' % self.addr)
44 48
         zmq.device(zmq.FORWARDER, self.socket, self.socket)
45 49
 
5  docs/examples/lib/internal_ipkernel.py
@@ -14,10 +14,7 @@ def pylab_kernel(gui):
14 14
     """Launch and return an IPython kernel with pylab support for the desired gui
15 15
     """
16 16
     kernel = IPKernelApp()
17  
-    # FIXME: we're hardcoding the heartbeat port b/c of a bug in IPython 0.11
18  
-    # that will set it to 0 if not specified.  Once this is fixed, the --hb
19  
-    # parameter can be omitted and all ports will be automatic
20  
-    kernel.initialize(['python', '--pylab=%s' % gui, '--hb=19999',
  17
+    kernel.initialize(['python', '--pylab=%s' % gui,
21 18
                        #'--log-level=10'
22 19
                        ])
23 20
     return kernel
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.