-
Notifications
You must be signed in to change notification settings - Fork 32
Kernel Stop Fix #468
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
Closed
Closed
Kernel Stop Fix #468
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a05e834
Blocking stop of sockets
rakhmaevao 7bdf913
Added e2e test for multiply kernel restarting test case
rakhmaevao 6342fb8
Cleanup
rakhmaevao 041ca4b
Linting. But only my files...
rakhmaevao b764b8a
Add mypy instruction
rakhmaevao 89e6f02
Cleanup
rakhmaevao 09aeec8
Up version
rakhmaevao de5fc83
Removed code that was backwards incompatible with 3.9 syntax
rakhmaevao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.7.5" | ||
__version__ = "0.7.6" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import json | ||
import urllib | ||
import uuid | ||
|
||
import requests | ||
import structlog | ||
from websocket import create_connection | ||
|
||
logger = structlog.get_logger() | ||
|
||
|
||
class JupyverseAdapter: | ||
def __init__(self, base_url): | ||
self.__netloc = urllib.parse.urlparse(base_url).netloc | ||
|
||
def new_session(self) -> str: | ||
kernel_name = str(uuid.uuid4()) | ||
response = requests.post( | ||
f"http://{self.__netloc}/api/sessions", | ||
json={ | ||
"kernel": {"name": "python3"}, | ||
"name": kernel_name, | ||
"path": kernel_name, | ||
"type": "console", | ||
}, | ||
) | ||
response.raise_for_status() | ||
response_json = response.json() | ||
kernel_id = response_json["kernel"]["id"] | ||
session_id = response_json["id"] | ||
logger.info("Created kernel %s with new session %s.", kernel_id, session_id) | ||
return kernel_id, session_id | ||
|
||
def kernel_info_request(self, kernel_id: str, session_id: str): | ||
session_id = str(uuid.uuid4()) | ||
ws = create_connection( | ||
f"ws://{self.__netloc}/api/kernels/{kernel_id}/channels?session_id={session_id}" | ||
) | ||
while True: | ||
ws.send( | ||
json.dumps( | ||
{ | ||
"channel": "shell", | ||
"header": { | ||
"date": "2025-03-07T18:09:53.949Z", | ||
"msg_id": "45331fc8-21fa-49b1-b115-4153c6af9df1", | ||
"msg_type": "kernel_info_request", | ||
"session": session_id, | ||
"username": "", | ||
"version": "5.2", | ||
}, | ||
"parent_header": {}, | ||
"metadata": {}, | ||
"content": {}, | ||
} | ||
) | ||
) | ||
msg = json.loads(ws.recv()) | ||
if msg["header"]["msg_type"] == "kernel_info_reply": | ||
break | ||
ws.close() | ||
|
||
def stop_kernel(self, kernel_id: str) -> None: | ||
response = requests.delete(f"http://{self.__netloc}/api/kernels/{kernel_id}") | ||
response.raise_for_status() | ||
logger.info("Stopped kernel %s.", kernel_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
from .jupyverse_adapter import JupyverseAdapter | ||
|
||
|
||
@pytest.mark.parametrize("auth_mode", ("noauth",)) | ||
@pytest.mark.parametrize("clear_users", (False,)) | ||
def test_multiple_kernel_restarts(start_jupyverse): | ||
url = start_jupyverse | ||
jupyverse_adapter = JupyverseAdapter(url) | ||
for _ in range(5): | ||
kernel_id, session_id = jupyverse_adapter.new_session() | ||
jupyverse_adapter.kernel_info_request(kernel_id, session_id) | ||
jupyverse_adapter.stop_kernel(kernel_id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How does this fix the bug?
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.
Hi. Sorry for being pushy. I don't want to seem like a bore. But I really want to contribute to this project.
The solution is to ensure that sockets are closed when the function is finished. Otherwise, we would exit the taskgroup without waiting for it to finish. This will allow them to be opened correctly when restarting.
My test passes on my commit. It fails on the main branch.
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.
Thanks for your interest in the project, but I don't think your PR fixes the bug.
I'm working on a fix, I will open a PR soon.
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.
Excellent. Then I will close this PR. And I will wait for yours. I will be able to run my test on it, so that you can be sure of the fact of the correction.