-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NbserverStopApp: stop notebooks through cli - jupyter notebook stop <… #2388
Changes from all commits
cd3233f
219c762
b6ac73c
8b20dcc
277d000
ed4de77
b2f63b4
44df51a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,6 +346,33 @@ def start(self): | |
self.log.info("Wrote hashed password to %s" % self.config_file) | ||
|
||
|
||
class NbserverStopApp(JupyterApp): | ||
version = __version__ | ||
description="Stop currently running notebook server for a given port" | ||
|
||
port = Integer(8888, config=True, | ||
help="Port of the server to be killed. Default 8888") | ||
|
||
def parse_command_line(self, argv=None): | ||
super(NbserverStopApp, self).parse_command_line(argv) | ||
if self.extra_args: | ||
self.port=int(self.extra_args[0]) | ||
|
||
def start(self): | ||
servers=list_running_servers(self.runtime_dir) | ||
server=next((server for server in servers if server.get('port')==self.port),None) | ||
if server: os.kill(server.get('pid'), signal.SIGTERM) | ||
else: | ||
ports=[s.get('port') for s in list_running_servers(self.runtime_dir)] | ||
if ports: | ||
print("There is currently no server running on port {}.".format(self.port)) | ||
print("Ports currently in use:") | ||
for port in ports: print("\t* {}".format(port)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This branch should have exit code 1 as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
else: | ||
print("There are currently no running servers") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also end with |
||
self.exit(1) | ||
|
||
|
||
class NbserverListApp(JupyterApp): | ||
version = __version__ | ||
description="List currently running notebook servers." | ||
|
@@ -449,6 +476,7 @@ class NotebookApp(JupyterApp): | |
|
||
subcommands = dict( | ||
list=(NbserverListApp, NbserverListApp.description.splitlines()[0]), | ||
stop=(NbserverStopApp, NbserverStopApp.description.splitlines()[0]), | ||
password=(NotebookPasswordApp, NotebookPasswordApp.description.splitlines()[0]), | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can now reuse the
servers
variable here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha - yeah, that was the very first thing i did, back before my initial commit, but
list_running_servers
returns an iterator so it doesn't work...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, OK then. Thanks, merging :-)