Hi Jeremy,

For a Python kernel, try this in the last cell:

%%javascript
Jupyter.notebook.session.delete();

It's borrowed 
from 
https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/menubar.js#L225.
 
The additional close_window logic in the notebook code probably won't work 
in the cell because the action is not directly triggered by a user click.

Cheers,
Pete

On Tuesday, November 8, 2016 at 11:43:01 AM UTC-8, Jeremy Douglass wrote:
>
> Can a Jupyter notebook programmatically halt itself, such that it no 
> longer appears in the "Running" tab?
>
> At the end of a notebook "Run All", I would like the last notebook cell to 
> contain code, and for that code to trigger the equivalent of:
>
>    - the "Running tab > Shutdown notebook" action
>    - ...or, failing that, the "Close and Halt" menu item
>    - ...or, failing that, the "Kernel > Interrupt" menu item
>    
> Can this be done with javascript, or with %magic, or something else?
>
> I am running the Docker image Jupyer Datascience Notebook 
> <https://github.com/jupyter/docker-stacks/blob/master/datascience-notebook/Dockerfile>,
>  
> not JupyterHub.
>
> I have tried to review related information, but none of these answered my 
> question:
>
>    1. keyboard shortcuts to close and halt 
>    <https://github.com/jupyter/notebook/issues/1097>
>    2. handling leftover singlehubs and kernels 
>    <https://groups.google.com/forum/#!msg/jupyter/sRhbV9UOwIw/Pwq23I_YAAAJ>
>    3. server cleanup on browser-exit notebooks 
>    <https://groups.google.com/forum/#!msg/jupyter/Qqd2MeL9R1g/jyS4mawADQAJ>
>    4. the cull-idle script for JupyterHub 
>    <https://github.com/jupyterhub/jupyterhub/tree/master/examples/cull-idle>
>    5. request to automatically shut down inactive notebooks 
>    <https://github.com/ipython/ipython/issues/5539>
>
>
> In certain use cases, idle notebook cruft is a huge problem. Information 
> isn't exposed that makes identifying an idle notebook easier, and tools for 
> culling notebooks are still wishlist items -- the consensus is it is hard 
> to define idle, and hard to intervene with the browser in certain ways 
> (e.g. event-on-tab-close).
>
> I'm trying to cut the gordian knot by having a run-all notebook explicitly 
> declare the notebook is halted / interrupted / done / closed as its last 
> act. This seems like it should be possible, as it is a consequence of a 
> user action (Run).
>
> Is it possible? Or are there other ways of accomplishing this?
>
>
>

-- 
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/890e47f5-dfb3-47fb-a373-af2dcd81ef60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to