{"action":"created","issue":{"url":"https://api.github.com/repos/jupyter/notebook/issues/1880","repository_url":"https://api.github.com/repos/jupyter/notebook","labels_url":"https://api.github.com/repos/jupyter/notebook/issues/1880/labels{/name}","comments_url":"https://api.github.com/repos/jupyter/notebook/issues/1880/comments","events_url":"https://api.github.com/repos/jupyter/notebook/issues/1880/events","html_url":"https://github.com/jupyter/notebook/issues/1880","id":188112641,"number":1880,"title":"Can a Jupyter notebook programmatically halt itself?","user":{"login":"jeremydouglass","id":798570,"avatar_url":"https://avatars.githubusercontent.com/u/798570?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydouglass","html_url":"https://github.com/jeremydouglass","followers_url":"https://api.github.com/users/jeremydouglass/followers","following_url":"https://api.github.com/users/jeremydouglass/following{/other_user}","gists_url":"https://api.github.com/users/jeremydouglass/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydouglass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydouglass/subscriptions","organizations_url":"https://api.github.com/users/jeremydouglass/orgs","repos_url":"https://api.github.com/users/jeremydouglass/repos","events_url":"https://api.github.com/users/jeremydouglass/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydouglass/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-08T21:48:00Z","updated_at":"2016-11-10T20:04:50Z","closed_at":null,"body":"Can a Jupyter notebook programmatically halt itself, such that the notebook no longer appears in the \"Running\" tab?\r\n\r\nAt 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:\r\n\r\n-  the \"Running tab > Shutdown notebook\" action\r\n-  ...or, failing that, the \"Close and Halt\" menu item\r\n\r\nCan this be done with javascript, or with %magic, or something else?\r\n\r\nI am running the latest Docker image [Jupyer Datascience Notebook](https://github.com/jupyter/docker-stacks/blob/master/datascience-notebook/Dockerfile), not JupyterHub.\r\n\r\n----------\r\n\r\n[forum cross-posted](https://groups.google.com/forum/#!topic/jupyter/3zAVHofQykg)"},"comment":{"url":"https://api.github.com/repos/jupyter/notebook/issues/comments/259793016","html_url":"https://github.com/jupyter/notebook/issues/1880#issuecomment-259793016","issue_url":"https://api.github.com/repos/jupyter/notebook/issues/1880","id":259793016,"user":{"login":"jeremydouglass","id":798570,"avatar_url":"https://avatars.githubusercontent.com/u/798570?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydouglass","html_url":"https://github.com/jeremydouglass","followers_url":"https://api.github.com/users/jeremydouglass/followers","following_url":"https://api.github.com/users/jeremydouglass/following{/other_user}","gists_url":"https://api.github.com/users/jeremydouglass/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydouglass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydouglass/subscriptions","organizations_url":"https://api.github.com/users/jeremydouglass/orgs","repos_url":"https://api.github.com/users/jeremydouglass/repos","events_url":"https://api.github.com/users/jeremydouglass/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydouglass/received_events","type":"User","site_admin":false},"created_at":"2016-11-10T20:04:50Z","updated_at":"2016-11-10T20:04:50Z","body":"Yes, a Jupyter notebook can programmatically halt itself.\r\n\r\nUse a cell at the end of an iPython notebook like this:\r\n\r\n    %%javascript\r\n    Jupyter.notebook.session.delete();\r\n\r\n-  On \"Run All\" the final %%javascript cell \"Jupyter.notebook.session.delete();\" correctly stops the notebook.\r\n-  The notebook interface shows \"No Kernel\", the Running tab no longer lists the notebook.\r\n-  The previous cell **incorrectly** still shows a running status [ * ], however the output from taht cell has already returned.\r\n\r\nRestart the stopped notebook with:\r\n\r\n-  Menu > Kernel > Restart ... \"Dead Kernel\" warning > Try restarting now\r\n-  ...or refresh the browser tab.\r\n\r\nA demo ipynb file is posted on the [forum thread](https://groups.google.com/forum/#!topic/jupyter/3zAVHofQykg)"}}
{"actor":{"display_login":"jeremydouglass"}}