Skip to content

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ $RECYCLE.BIN/
.jupyter_ystore.db
.jupyter_ystore.db-journal
fps_cli_args.toml
.fileid.db

# pixi environments
.pixi
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Packaging

```bash
```shell
rm -rf dist; python setup.py sdist bdist_wheel
cd plugins/auth ; rm -rf dist && python setup.py sdist bdist_wheel ; cp dist/* ../../dist/ ; cd ../..
cd plugins/contents ; rm -rf dist && python setup.py sdist bdist_wheel ; cp dist/* ../../dist/ ; cd ../..
Expand All @@ -14,3 +14,21 @@ cd plugins/yjs ; rm -rf dist && python setup.py sdist bdist_wheel ; cp di

twine upload dist/*
```

## Running Tests

```shell
hatch run dev.jupyterlab-auth:test
```

## Linting

```shell
hatch run dev.jupyterlab-auth:lint
```

## Type Checking

```shell
hatch run dev.jupyterlab-auth:typecheck0
```
2 changes: 1 addition & 1 deletion plugins/kernels/fps_kernels/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.5"
__version__ = "0.7.6"
8 changes: 4 additions & 4 deletions plugins/kernels/fps_kernels/kernel_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ async def start(
async def stop(self) -> None:
try:
async with create_task_group() as tg:
tg.start_soon(self.shell_channel.stop)
tg.start_soon(self.stdin_channel.stop)
tg.start_soon(self.control_channel.stop)
tg.start_soon(self.iopub_channel.stop)
await tg.start(self.shell_channel.stop)
await tg.start(self.stdin_channel.stop)
await tg.start(self.control_channel.stop)
await tg.start(self.iopub_channel.stop)
Copy link
Collaborator

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?

Copy link
Author

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.

Copy link
Collaborator

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.

Copy link
Author

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.

except Exception:
pass

Expand Down
Empty file added tests/e2e/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions tests/e2e/jupyverse_adapter.py
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)
14 changes: 14 additions & 0 deletions tests/e2e/test_multiple_kernel_restarts.py
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)
Loading