Skip to content
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

PR: Shutdown kernel of the notebook before closing it #26

Merged
merged 4 commits into from
Jan 16, 2017

Conversation

dalthviz
Copy link
Member

Fixes #5

@dalthviz dalthviz added this to the v0.1 milestone Jan 15, 2017
@dalthviz dalthviz self-assigned this Jan 15, 2017
@@ -223,6 +229,29 @@ def close_client(self, index=None, client=None):
if index is not None:
client = self.tabwidget.widget(index)

session_url = url_path_join(client.server_url, 'api/sessions')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this sessions_url

@@ -223,6 +229,29 @@ def close_client(self, index=None, client=None):
if index is not None:
client = self.tabwidget.widget(index)

session_url = url_path_join(client.server_url, 'api/sessions')
session_req = requests.get(session_url).content.decode()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this one to sessions_req

content = json.loads(session_req)
kernel_id = None
for notebook in content:
if notebook['notebook']['path'] == client.path.replace('\\','/'):
Copy link
Member

@ccordoba12 ccordoba12 Jan 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replace part only needs to be applied on Windows.

kernel_id)
delete_req = requests.delete(delete_url)
if delete_req.status_code != 204:
QMessageBox.critical(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change critical here for warning.

@ccordoba12
Copy link
Member

Great job @dalthviz! I only left some minor comments to improve readability ;-)

@@ -223,6 +229,29 @@ def close_client(self, index=None, client=None):
if index is not None:
client = self.tabwidget.widget(index)

session_url = url_path_join(client.server_url, 'api/sessions')
session_req = requests.get(session_url).content.decode()
content = json.loads(session_req)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be sessions = json.loads(session_req)

session_req = requests.get(session_url).content.decode()
content = json.loads(session_req)
kernel_id = None
for notebook in content:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to for session in sessions:

# TODO: Eliminate the notebook from disk if it's an Untitled one
client.close()

# Note: notebook index may have changed after closing related widgets
self.tabwidget.removeTab(self.tabwidget.indexOf(client))
self.clients.remove(client)

def shutdown_kernel(self, client):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this method to NotebookClient. It fits better there than here.

_("The Jupyter Notebook server failed "
"to shutdown the kernel. "
"If you want to shutdown it you would "
"have to do it manually."
Copy link
Member

@ccordoba12 ccordoba12 Jan 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rewrite this as

The Jupyter Notebook server failed to shutdown the kernel associated with this notebook.
If you want to shut it down, you'll have to close Spyder.

"to shutdown the kernel. "
"If you want to shutdown it you would "
"have to do it manually."
"<br><br>Status code {}").format(delete_req.status_code))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line, I don't think we need to show the response's status code.

@ccordoba12
Copy link
Member

A couple more comments from me and then this will be ready :-)

@@ -12,6 +12,8 @@
import subprocess
import sys
import tempfile


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank

@ccordoba12
Copy link
Member

Thanks @dalthviz!

@ccordoba12 ccordoba12 merged commit fcd366b into spyder-ide:master Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants