##// END OF EJS Templates
remove hardcoded hb port from internal example...
MinRK -
Show More
@@ -1,68 +1,65 b''
1 1 #-----------------------------------------------------------------------------
2 2 # Imports
3 3 #-----------------------------------------------------------------------------
4 4
5 5 import subprocess
6 6 import sys
7 7
8 8 from IPython.zmq.ipkernel import IPKernelApp
9 9
10 10 #-----------------------------------------------------------------------------
11 11 # Functions and classes
12 12 #-----------------------------------------------------------------------------
13 13 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
24 21
25 22
26 23 def qtconsole_cmd(kernel):
27 24 """Compute the command to connect a qt console to an already running kernel
28 25 """
29 26 ports = ['--%s=%d' % (name, port) for name, port in kernel.ports.items()]
30 27 return ['ipython', 'qtconsole', '--existing'] + ports
31 28
32 29
33 30 class InternalIPKernel(object):
34 31
35 32 def init_ipkernel(self, backend):
36 33 # Start IPython kernel with GUI event loop and pylab support
37 34 self.ipkernel = pylab_kernel(backend)
38 35 # To create and track active qt consoles
39 36 self._qtconsole_cmd = qtconsole_cmd(self.ipkernel)
40 37 self.consoles = []
41 38
42 39 # This application will also act on the shell user namespace
43 40 self.namespace = self.ipkernel.shell.user_ns
44 41 # Keys present at startup so we don't print the entire pylab/numpy
45 42 # namespace when the user clicks the 'namespace' button
46 43 self._init_keys = set(self.namespace.keys())
47 44
48 45 # Example: a variable that will be seen by the user in the shell, and
49 46 # that the GUI modifies (the 'Counter++' button increments it):
50 47 self.namespace['app_counter'] = 0
51 48 #self.namespace['ipkernel'] = self.ipkernel # dbg
52 49
53 50 def print_namespace(self, evt=None):
54 51 print "\n***Variables in User namespace***"
55 52 for k, v in self.namespace.iteritems():
56 53 if k not in self._init_keys and not k.startswith('_'):
57 54 print '%s -> %r' % (k, v)
58 55 sys.stdout.flush()
59 56
60 57 def new_qt_console(self, evt=None):
61 58 self.consoles.append(subprocess.Popen(self._qtconsole_cmd))
62 59
63 60 def count(self, evt=None):
64 61 self.namespace['app_counter'] += 1
65 62
66 63 def cleanup_consoles(self, evt=None):
67 64 for c in self.consoles:
68 65 c.kill()
General Comments 0
You need to be logged in to leave comments. Login now