##// END OF EJS Templates
Notebook app debugging....
Brian E. Granger -
Show More
@@ -11,7 +11,7 b' import uuid'
11 11
12 12 import zmq
13 13
14 from IPython.config.configurable import Configurable
14 from IPython.config.configurable import LoggingConfigurable
15 15 from IPython.zmq.ipkernel import launch_kernel
16 16 from IPython.utils.traitlets import Instance, Dict, Unicode
17 17
@@ -23,17 +23,13 b' class DuplicateKernelError(Exception):'
23 23 pass
24 24
25 25
26 class KernelManager(Configurable):
26 class KernelManager(LoggingConfigurable):
27 27 """A class for managing multiple kernels."""
28 28
29 29 context = Instance('zmq.Context')
30 30 def _context_default(self):
31 31 return zmq.Context.instance()
32 32
33 logname = Unicode('')
34 def _logname_changed(self, name, old, new):
35 self.log = logging.getLogger(new)
36
37 33 _kernels = Dict()
38 34
39 35 @property
@@ -181,6 +177,6 b' class KernelManager(Configurable):'
181 177 from sessionmanager import SessionManager
182 178 return SessionManager(
183 179 kernel_id=kernel_id, kernel_manager=self,
184 config=self.config, context=self.context, logname=self.logname
180 config=self.config, context=self.context, log=self.log
185 181 )
186 182
@@ -6,6 +6,8 b''
6 6
7 7 import logging
8 8 import os
9 import signal
10 import sys
9 11
10 12 import zmq
11 13
@@ -16,7 +18,6 b' import tornado.ioloop'
16 18 tornado.ioloop = ioloop
17 19
18 20 from tornado import httpserver
19 from tornado import options
20 21 from tornado import web
21 22
22 23 from kernelmanager import KernelManager
@@ -28,7 +29,16 b' from handlers import ('
28 29 from routers import IOPubStreamRouter, ShellStreamRouter
29 30
30 31 from IPython.core.application import BaseIPythonApplication
32 from IPython.core.profiledir import ProfileDir
33 from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
31 34 from IPython.zmq.session import Session
35 from IPython.zmq.zmqshell import ZMQInteractiveShell
36 from IPython.zmq.ipkernel import (
37 flags as ipkernel_flags,
38 aliases as ipkernel_aliases,
39 IPKernelApp
40 )
41 from IPython.utils.traitlets import Dict, Unicode, Int, Any, List, Enum
32 42
33 43 #-----------------------------------------------------------------------------
34 44 # Module globals
@@ -37,13 +47,15 b' from IPython.zmq.session import Session'
37 47 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
38 48 _kernel_action_regex = r"(?P<action>restart|interrupt)"
39 49
50 LOCALHOST = '127.0.0.1'
51
40 52 #-----------------------------------------------------------------------------
41 53 # The Tornado web application
42 54 #-----------------------------------------------------------------------------
43 55
44 56 class NotebookWebApplication(web.Application):
45 57
46 def __init__(self, kernel_manager, log):
58 def __init__(self, kernel_manager, log, kernel_argv):
47 59 handlers = [
48 60 (r"/", MainHandler),
49 61 (r"/kernels", KernelHandler),
@@ -61,7 +73,9 b' class NotebookWebApplication(web.Application):'
61 73
62 74 self.kernel_manager = kernel_manager
63 75 self.log = log
76 self.kernel_argv = kernel_argv
64 77 self._routers = {}
78 self._session_dict = {}
65 79
66 80 #-------------------------------------------------------------------------
67 81 # Methods for managing kernels and sessions
@@ -72,9 +86,11 b' class NotebookWebApplication(web.Application):'
72 86 return self.kernel_manager.kernel_ids
73 87
74 88 def start_kernel(self):
75 # TODO: pass command line options to the kernel in start_kernel()
76 kernel_id = self.kernel_manager.start_kernel()
89 kwargs = dict()
90 kwargs['extra_arguments'] = self.kernel_argv
91 kernel_id = self.kernel_manager.start_kernel(**kwargs)
77 92 self.log.info("Kernel started: %s" % kernel_id)
93 self.log.debug("Kernel args: %r" % kwargs)
78 94 self.start_session_manager(kernel_id)
79 95 return kernel_id
80 96
@@ -87,7 +103,6 b' class NotebookWebApplication(web.Application):'
87 103 shell_router = ShellStreamRouter(shell_stream)
88 104 self._routers[(kernel_id, 'iopub')] = iopub_router
89 105 self._routers[(kernel_id, 'shell')] = shell_router
90 self.log.debug("Session manager started for kernel: %s" % kernel_id)
91 106
92 107 def kill_kernel(self, kernel_id):
93 108 sm = self._session_dict.pop(kernel_id)
@@ -139,9 +154,9 b' aliases = dict(ipkernel_aliases)'
139 154
140 155 aliases.update(dict(
141 156 ip = 'IPythonNotebookApp.ip',
142 port = 'IPythonNotebookApp.port'
157 port = 'IPythonNotebookApp.port',
143 158 colors = 'ZMQInteractiveShell.colors',
144 editor = 'IPythonWidget.editor',
159 editor = 'RichIPythonWidget.editor',
145 160 ))
146 161
147 162 #-----------------------------------------------------------------------------
@@ -160,12 +175,17 b' class IPythonNotebookApp(BaseIPythonApplication):'
160 175 """
161 176
162 177 classes = [IPKernelApp, ZMQInteractiveShell, ProfileDir, Session,
163 KernelManager, SessionManager]
178 KernelManager, SessionManager, RichIPythonWidget]
164 179 flags = Dict(flags)
165 180 aliases = Dict(aliases)
166 181
167 182 kernel_argv = List(Unicode)
168 183
184 log_level = Enum((0,10,20,30,40,50,'DEBUG','INFO','WARN','ERROR','CRITICAL'),
185 default_value=logging.INFO,
186 config=True,
187 help="Set the log level by value or name.")
188
169 189 # connection info:
170 190 ip = Unicode(LOCALHOST, config=True,
171 191 help="The IP address the notebook server will listen on."
@@ -185,10 +205,10 b' class IPythonNotebookApp(BaseIPythonApplication):'
185 205
186 206 self.kernel_argv = list(argv) # copy
187 207 # kernel should inherit default config file from frontend
188 self.kernel_argv.append("KernelApp.parent_appname='%s'"%self.name)
208 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
189 209 # scrub frontend-specific flags
190 210 for a in argv:
191 if a.startswith('--') and a[2:] in qt_flags:
211 if a.startswith('-') and a.lstrip('-') in notebook_flags:
192 212 self.kernel_argv.remove(a)
193 213
194 214 def init_kernel_manager(self):
@@ -198,10 +218,17 b' class IPythonNotebookApp(BaseIPythonApplication):'
198 218 # Create a KernelManager and start a kernel.
199 219 self.kernel_manager = KernelManager(config=self.config, log=self.log)
200 220
221 def init_logging(self):
222 super(IPythonNotebookApp, self).init_logging()
223 # This prevents double log messages because tornado use a root logger that
224 # self.log is a child of. The logging module dipatches log messages to a log
225 # and all of its ancenstors until propagate is set to False.
226 self.log.propagate = False
227
201 228 def initialize(self, argv=None):
202 229 super(IPythonNotebookApp, self).initialize(argv)
203 self.init_kernel_mananger()
204 self.web_app = NotebookWebApplication()
230 self.init_kernel_manager()
231 self.web_app = NotebookWebApplication(self.kernel_manager, self.log, self.kernel_argv)
205 232 self.http_server = httpserver.HTTPServer(self.web_app)
206 233 self.http_server.listen(self.port)
207 234
@@ -70,7 +70,7 b' class SessionManager(SessionFactory):'
70 70 def create_connected_stream(self, port, socket_type):
71 71 sock = self.context.socket(socket_type)
72 72 addr = "tcp://%s:%i" % (self.kernel_manager.get_kernel_ip(self.kernel_id), port)
73 self.log.info("Connecting to: %s, %r" % (addr, socket_type))
73 self.log.info("Connecting to: %s" % addr)
74 74 sock.connect(addr)
75 75 return ZMQStream(sock)
76 76
@@ -195,7 +195,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
195 195 qtconsole=('IPython.frontend.qt.console.qtconsoleapp.IPythonQtConsoleApp',
196 196 """Launch the IPython Qt Console."""
197 197 ),
198 hotebook=('IPython.frontend.html.notebook.notebookapp.IPythonNotebookApp',
198 notebook=('IPython.frontend.html.notebook.notebookapp.IPythonNotebookApp',
199 199 """Launch the IPython HTML Notebook Server"""
200 200 ),
201 201 profile = ("IPython.core.profileapp.ProfileApp",
General Comments 0
You need to be logged in to leave comments. Login now