Skip to content

The Python kernel's control thread may hang during shutdowns #7142

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
seeM opened this issue Apr 7, 2025 · 3 comments
Closed

The Python kernel's control thread may hang during shutdowns #7142

seeM opened this issue Apr 7, 2025 · 3 comments
Assignees
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: python

Comments

@seeM
Copy link
Contributor

seeM commented Apr 7, 2025

The Python kernel's control thread may hang during shutdowns. See this Playwright report for example.

The last few logs before the hang:

[Python] [PositronIPKernelApp] Control received: {'header': {'msg_id': 'defdcdb49e', 'msg_type': 'shutdown_request', 'session': 'python-0d121134', 'username': 'runner', 'date': datetime.datetime(2025, 4, 4, 21, 16, 46, 731000, tzinfo=tzutc()), 'version': '5.3'}, 'msg_id': 'defdcdb49e', 'msg_type': 'shutdown_request', 'parent_header': {}, 'metadata': {}, 'content': {'restart': False}, 'buffers': []}
[Python] [positron.positron_ipkernel] Shutting down the kernel
[Python] [positron.help] Stopping pydoc server thread
[Python] [positron.help] Pydoc server thread stopped
[Python] [PositronIPKernelApp] Kernel has no children.
[Python] [PositronIPKernelApp] {'header': {'msg_id': '4ff340cc-0dac95f225aa852099896c76_155264_59', 'msg_type': 'shutdown_reply', 'username': 'runner', 'session': '4ff340cc-0dac95f225aa852099896c76', 'date': datetime.datetime(2025, 4, 4, 21, 16, 47, 7045, tzinfo=datetime.timezone.utc), 'version': '5.3'}, 'msg_id': '4ff340cc-0dac95f225aa852099896c76_155264_59', 'msg_type': 'shutdown_reply', 'parent_header': {'msg_id': 'defdcdb49e', 'msg_type': 'shutdown_request', 'session': 'python-0d121134', 'username': 'runner', 'date': datetime.datetime(2025, 4, 4, 21, 16, 46, 731000, tzinfo=tzutc()), 'version': '5.3'}, 'content': {'status': 'ok', 'restart': False}, 'metadata': {}, 'tracker': <zmq.sugar.tracker.MessageTracker object at 0x7fe8024fbd90>}
[Python] [PositronIPKernelApp] Stopping control ioloop
[Python] [PositronIPKernelApp] Stopping shell ioloop
[Python] [asyncio] Close <_UnixSelectorEventLoop running=False closed=False debug=True>
[Python] [PositronIPKernelApp] Cleaning up sockets
[Python] [PositronIPKernelApp] Closing heartbeat channel
[Python] [PositronIPKernelApp] Closing iopub channel
[Python] [PositronIPKernelApp] Closing control thread
@seeM seeM added area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: python labels Apr 7, 2025
@seeM seeM added this to the 2025.05.0 Pre-Release milestone Apr 7, 2025
@seeM seeM self-assigned this Apr 7, 2025
@seeM
Copy link
Contributor Author

seeM commented Apr 7, 2025

This may be addressed in ipykernel once v7 comes out of pre-release. There was a huge refactor to the way that concurrency is handled in ipython/ipykernel#1079.

@seeM
Copy link
Contributor Author

seeM commented Apr 7, 2025

I haven't been successful tracking this down, but I suspect it is a pre-existing issue in ipykernel. Some options below:

Option A: The supervisor currently waits for a kernel process to exit before it considers a kernel exited. We could update it to wait only for the shutdown_reply message. If the process hangs around afterwards, Positron could kill it in the background and log it somewhere.

Option B: More simply, we could timeout if the control thread doesn't exit quickly (or more generally, if the shutdown sequence takes longer than expected) and forcefully exit, perhaps with an error status code.

seeM added a commit that referenced this issue Apr 8, 2025
Address #7142 by dropping the control thread if it doesn't exit after 5 seconds.

### QA Notes

Hopefully this reduces flakiness in CI, else we can take another look
with the new logs.

e2e: @:sessions @:console
@jonvanausdeln
Copy link
Contributor

We haven't seen this issue in automation since the fix. We'll keep an eye on it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: python
Projects
None yet
Development

No branches or pull requests

2 participants