On 8 June 2017 at 04:04, Brendan Barnwell <[email protected]> wrote:

> What I would like is the ability to start a notebook server that would
> automatically shut down once the associated browser is closed.  Looking at
> old messages on the list, I get the impression this isn't possible.  Is
> that correct?
>

With a special-purpose browser that knows about the notebook server, yes -
the browser can either use SIGTERM when it closes to shut down the notebook
server, or when notebook 5.1 is released, it will be able to POST to
/api/shutdown

https://github.com/jupyter/notebook/pull/2507


> It seems like it would be possible to implement this by having JavaScript
> in the notebook page send keepalive messages back to the server.  These
> would serve as a sort of "dead man's switch" --- as long as the page
> remained open, the server would remain alive, but when the browser (or tab
> in a multi-tab browser) was closed, the cessation of keepalive messages
> would tell the server to shut itself down.  Is this feasible?
>

Feasible, and we already monitor connectivity to the kernel, but I don't
think we'd ever do that by default - we don't want to kill the notebook
server if your connection to it goes down. Even locally, 'keep alive'
messages can be tricky to get right when computers go into standby.

Plus, of course, many people expect their notebook server to stay running
without an open browser tab on it.


> Failing that, I've also been looking for documentation on how to
> programmatically start the notebook server.  That is, supposing I'm running
> some Python code, how can I, from within that code, do the equivalent of
> "jupyter notebook --no-browser", and get the login token returned as a
> string so that I can redirect my wrapper to the appropriate URL?  Right now
> the only way I can see is to actually run jupyter using subprocess and
> parse the output, but that seems rather awkward.  Is there a part of the
> notebook that I can import as a module and do something like "server =
> notebook.start_server()" and then "token = server.token"?
>

Not quite as neat as that, but you can get info on the current user's
running notebook servers by calling:

notebook.notebookapp.list_running_servers()

You should be able to find the one you've just started as a subprocess by
checking the PIDs. That's easier than parsing info from stdout/stderr.

Thomas

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CAOvn4qi4Y%3Dj1h4aguqyJk-w2Oc5OThrxghM-%2Bxq2G0XpZ4695g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to