Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow for additional tornado handlers in the notebook server #2694

Closed
wants to merge 1 commit into from

3 participants

@filmor

This makes the notebook server (at least for me) a bit more useful, since I can easily use the notebook's profile and provide a websocket-based service in the same context.

@Carreau
Owner

Out of curiosity, what are using in parallel ?

@filmor

I've written a database connector that I expose using different python handlers via a tornado websocket. In the end I want to be able to write those handlers based on cells from notebooks.

@Carreau
Owner

Sorry for the delay to respond,
You want to connect cell to those db through websoket,
Is it to "store" those cells, to edit something ?
Can't you go through the kernel to do that?

I'm just trying to see how this could fit in IPython future plan, and in particular multi-user and security.
Or wether this already falls into the multiple backend to store things.

@filmor

This maybe is a bit to hacky, point is, I want to run a specific IPython notebook server on the same port as some other applications (namely the database connector, that may also be used in Javascript widgets in the notebook itself for prototyping purposes). However what I just realised I would actually like to do would be to start a tornado server and use a notebook server as a handler for "/ipython/(.*)", by using a profile, i.e. I want to do something like ("ipython/(.*)", IPython.NotebookHandler(profile="nbserver")). This pull request emulates this behaviour by adding the other handlers to the notebook's tornado.

@Carreau
Owner

Ok, I'm not sure I totally follow,

serving under /ipython/* can be done with --NotebookApp.base_project_url but you want a handler for databases on the same port for your cells to access it.

I'm not quite sure of what you want to do with those handler. You state that you want to do it with javascript widget, but don't you want the js widget to acces this throught the kernel ? I do understand that for prototyping purpose this is usefull, but if we ship it, people will start relying on it for other purpose.

Isn't it possible to do the other way around ?
A proxy that will dispatch the request either to IPython if url start with 'ipython' or to any other program otherwise ?

If I had to guess, I would say nginx, or a simple node program.

If there is a positive answer I'm really interest in knowing how to do that for my own config. It's on the 1000 things I wan't to try and haven't got time to do.

@ellisonbg
Owner
@Carreau
Owner

Not doable with nginx yet because of websocket, planed for 1.3.
Potentially doable with node, but there is a huge new bug in using base_project_url in current version that prevent from doing that.

@Carreau
Owner

@filmor

I did it with node

Mapped localhost:8000/ipython/* to localhost:8888/ipython/*
And at the same time localhost:8000/whatever/* to anotherhost:1234/somethingelse/*

Advantage is that you can change the bindings live without having to restart IPython notebook server.
(and works also with other programs than IPython)

Are you interested ?

@ellisonbg
Owner

So here is the rough outline of why we don't want to go in this direction. The current scope of the ipython notebook app is that it is the ipython notebook application. By, I mean that we want to limit its usefulness to serving notebooks only. Allowing arbitrary handlers turns the main notebook script into a sort of generic web framework that just happens to have an IPython notebook in it. That is too broad of a scope.

We do want people to write more general web applications that have notebooks in them, but these are outside the scope of ipython and should thus be done as separate projects. But, we do want to make it easy for people to write these notebook-including web apps. Some of the things we are thinking about:

  • Making our html/css/js more modular to allow people to grab only the pieces they need.
  • Refactoring our handlers to allow the same modularity.
  • Turning some of our main notebook app into libraries that other people can use.

Eventually, you should be able to grab the pieces you need, and create your own main web app script and be of to the races. BUT, I realize we are not there yet, so solutions like Matthias's node proxy are very attractive.

With these things in mind, are you OK if we close this PR?

@filmor

I am indeed, thanks. I'll think I'll go with a proxy solution for now.

@filmor filmor closed this
@Carreau
Owner

BTW, I released the proof of concept of proxy on npm and here is the source I'll be happy to get improvement.

Please ping me if you have issues using it.

@ellisonbg
Owner

@filmor thanks for understanding. Look forward to seeing how you end up using the notebook in your web apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +7 −0 IPython/frontend/html/notebook/notebookapp.py
View
7 IPython/frontend/html/notebook/notebookapp.py
@@ -169,6 +169,8 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
cookie_name='username-%s' % uuid.uuid4(),
)
+ additional_handlers = settings_overrides.pop("handlers", [])
+
# allow custom overrides for the tornado web app.
settings.update(settings_overrides)
@@ -179,6 +181,11 @@ def __init__(self, ipython_app, kernel_manager, notebook_manager,
new_handler = tuple([pattern]+list(handler[1:]))
new_handlers.append( new_handler )
+ new_handlers += [
+ (a[0], import_item(a[1])) + tuple(a[2:])
+ for a in additional_handlers
+ ]
+
super(NotebookWebApplication, self).__init__(new_handlers, **settings)
self.kernel_manager = kernel_manager
Something went wrong with that request. Please try again.