Open mrocklin opened 5 years ago
Very close!
from notebook.notebookapp import NotebookApp
app = NotebookApp()
app.initialize([])
Square brackets are the command line arguments. Might want to set port and token, if you actually want to talk to it.
I've never given it a custom io_loop, though... Probably have to overload .start, as it always use the current one.
More:
https://gist.github.com/bollwyvl/bd56b58ba0a078534272043327c52bd1
On Tue, Sep 10, 2019, 13:27 Matthew Rocklin notifications@github.com wrote:
I have an existing Python process running a Tornado web application (Dask) and I would like to run a Jupyter notebook server from within this process, on the same event loop. I looked around and couldn't find any good documentation on how to start Jupyter from within Python. Is this easy?
Ideally I would do something like the following:
from notebook import Server
io_loop = tornado.ioloop.IOLoop.current()
server = Server(io_loop=io_loop)await server.start()
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jupyter/notebook/issues/4873?email_source=notifications&email_token=AAALCRHIHL3ZSSM5VAMXR5DQI7KJTA5CNFSM4IVKQCT2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HKQKPZA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAALCRCWQ7HVOUGTH3PYDWDQI7KJTANCNFSM4IVKQCTQ .
That works! Nice.
OK, so if providing an event loop is hard, I imagine that it's also quite hard to provide my own, already running Tornado HTTPServer. True? It would be interesting to have only one of these running, assuming that Dask and Jupyter don't have any overlapping routes.
I think one could...
init_webapp
could be broken up to not conflate the initialization of NotebookApp.web_app
and NotebookApp.http_server
(which pretty much just owns the port and the SSL)Application.__call__
how to (sometimes) dispatch to this new NotebookApp.__call__
(which i've never seen overload, but...)
web.Application
subclass someplace?i've usually been interested in taking the already-running, somewhat idiosyncratic notebook tornado loop/server/app to run other things in process so i can muck about with their workings in response to yet other things (usually, kernels, contents, and nb/lab extension-interfacing REST APIs). I must confess, dask has not been one of them, preferring to leave it on the other side of the proxy :P
It's always better to keep out the riff raff :)
On Tue, Sep 10, 2019, 5:35 PM Nicholas Bollweg notifications@github.com wrote:
I think one could...
- ... overload NotebookApp.init_webapp https://github.com/jupyter/notebook/blob/6.0.1/notebook/notebookapp.py#L1434 to inject an existing http_server...
- init_webapp could be broken up to not conflate the initialization of NotebookApp.web_app and NotebookApp.http_server (which pretty much just owns the port and the SSL)
- but the relationship has been 1:1 to date, as far as i can tell
- ... and teach the originally-launched Application.call https://github.com/tornadoweb/tornado/blob/v6.0.3/tornado/web.py#L2164 how to (sometimes) dispatch to this new NotebookApp.call (which i've never seen overload, but...)
- ... or use the not-exactly-newfangled https://github.com/tornadoweb/tornado/pull/1806 callable adapter https://github.com/tornadoweb/tornado/blob/v6.0.3/tornado/httpserver.py#L237 to multiplex
- ... or somehow bolt them all together with inheritance
- do you have a web.Application subclass someplace?
i've usually been interested in taking the already-running, somewhat idiosyncratic https://github.com/jupyter/notebook/blob/6.0.1/notebook/notebookapp.py#L47 notebook tornado loop/server/app to run other things in process so i can muck about with their workings in response to yet other things (usually, kernels, contents, and nb/lab extension-interfacing REST APIs). I must confess, dask has not been one of them, preferring to leave it on the other side of the proxy :P
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jupyter/notebook/issues/4873?email_source=notifications&email_token=AACKZTCZ7UZGCVYBFCN7JVTQJA4M7A5CNFSM4IVKQCT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6M4LVI#issuecomment-530171349, or mute the thread https://github.com/notifications/unsubscribe-auth/AACKZTGQPSRQFBQPSUZN4MTQJA4M7ANCNFSM4IVKQCTQ .
I have an existing Python process running a Tornado web application (Dask) and I would like to run a Jupyter notebook server from within this process, on the same event loop. I looked around and couldn't find any good documentation on how to start Jupyter from within Python. Is this easy?
Ideally I would do something like the following: