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

Slower atexit methods do not run to completion #16276

Open
parantapa opened this issue May 2, 2024 · 5 comments
Open

Slower atexit methods do not run to completion #16276

parantapa opened this issue May 2, 2024 · 5 comments
Labels

Comments

@parantapa
Copy link

parantapa commented May 2, 2024

Description

Cleanup methods that are slower do not run to completion when restarting kernel.

Reproduce

  1. Create a new IPython notebook
  2. Create and execute a new cell with the following code

Example code:

import atexit
import time
from pathlib import Path

def write_hello():
    time.sleep(5)
    Path("hello.txt").write_text("hello")

atexit.register(write_hello)
  1. Click on "Restart kernel"
  2. The new file "hello.txt" was not created.

Expected behavior

The "hello.txt" should have been created.

Context

  • Operating System and version: ArchLinux
  • Browser and version: Firefox Developer version 125.0b6
  • JupyterLab version: 4.1.6

Additional info

Jupyter lab shows a TimeoutError on console.

[E 2024-05-02 10:50:31.388 ServerApp] Uncaught exception GET /api/kernels/28d27336-01eb-4fed-9b24-e5b4a1ae8ef4/channels?session_id=3fa3bd68-c341-4029-b71b-92c68bdc3ba6 (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/28d27336-01eb-4fed-9b24-e5b4a1ae8ef4/channels?session_id=3fa3bd68-c341-4029-b71b-92c68bdc3ba6', version='HTTP/1.1', remote_ip='127.0.0.1')
    Traceback (most recent call last):
      File "/home/parantapa/miniconda3/envs/notebook_env/lib/python3.11/site-packages/tornado/web.py", line 1790, in _execute
        result = await result
                 ^^^^^^^^^^^^
      File "/home/parantapa/miniconda3/envs/notebook_env/lib/python3.11/site-packages/jupyter_server/services/kernels/websocket.py", line 65, in get
        await self.pre_get()
      File "/home/parantapa/miniconda3/envs/notebook_env/lib/python3.11/site-packages/jupyter_server/services/kernels/websocket.py", line 59, in pre_get
        await self.connection.prepare()
      File "/home/parantapa/miniconda3/envs/notebook_env/lib/python3.11/site-packages/jupyter_server/services/kernels/connection/channels.py", line 318, in prepare
        raise TimeoutError(msg)
    TimeoutError: Kernel never reached an 'alive' state.

This error is gone when using a larger kernel_info_timeout.
However, the atexit method still does not run to completion.

@parantapa parantapa added the bug label May 2, 2024
Copy link

welcome bot commented May 2, 2024

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label May 2, 2024
@JasonWeill JasonWeill removed the status:Needs Triage Applied to new issues that need triage label May 7, 2024
@JasonWeill
Copy link
Contributor

@parantapa Thank you for opening this issue! Does this also happen when you use other apps, like VS Code, that support ipykernel? If so, this may be an issue upstream, which you can report here: https://github.com/ipython/ipykernel/issues

@parantapa
Copy link
Author

@JasonWeill It works as expected on when using IPython from shell. I do not use VS Code so I am unable to test on that.

I have been trying to find the spot in Jupyter Lab, Jupyter Server and Ipython that is responsible for killing the kernel. But I since I am not familiar enough, I haven't figured it out.

@krassowski
Copy link
Member

I have been trying to find the spot in Jupyter Lab, Jupyter Server and Ipython that is responsible for killing the kernel. But I since I am not familiar enough, I haven't figured it out.

This would be jupyter_client or ipykernel.

@krassowski
Copy link
Member

Though the timeout is raised from jupyter_server as your traceback indicates, so maybe you problem is that the timeout in jupyter_server is too short for your usecase? In any case the code you are looking for is not in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants