jupyter-server / jupyter-resource-usage

Jupyter Notebook Extension for monitoring your own Resource Usage
BSD 2-Clause "Simplified" License
473 stars 104 forks source link

Spurious `unknown message usage_request errors #214

Open nthiery opened 11 months ago

nthiery commented 11 months ago

Description

jupyter-error-messages now emits "usage_request" messages. However not all kernels support them, which may lead to error messages in the notebook:

ERROR: received unknown message
Message type: usage_request

See this discussion

Reproduce

  1. Install jupyterlab 4.0.4, jupyterlab-resource-usage 1.0.1 and e.g. xeus-cling 0.15.1 from conda-forge.
  2. Open a notebook and choose C++ as kernel
  3. Run some computations
  4. From time to time, the error will appear

(sorry, not great in terms of reproducibility :-) )

/cc @jtpio

welcome[bot] commented 11 months ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
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! :wave:
Welcome to the Jupyter community! :tada:

jtpio commented 11 months ago

Thanks @nthiery for opening the issue :+1:

This might be related to the logic to detect whether the kernel usage is supported:

https://github.com/jupyter-server/jupyter-resource-usage/blob/cbf962f881058a30e2ce6951018da1cc937b8929/jupyter_resource_usage/api.py#L14-L21

https://github.com/jupyter-server/jupyter-resource-usage/blob/cbf962f881058a30e2ce6951018da1cc937b8929/jupyter_resource_usage/api.py#L96-L107

These checks seem to be happening on the server extension regardless of which kernel is currently in use. Probably this means that if ipykernel is installed then the kernel usage will be enabled server side, even if another kernel is used in the notebook?

cc @echarles @krassowski @davidbrochart since this likely comes from the integration of the kernel usage panel in this repo: https://github.com/jupyter-server/jupyter-resource-usage/pull/164

krassowski commented 10 months ago

Yes, the code incorrectly assumes that the current kernel is always ipykernel. It also uses as of yet non-standard usage_request message. I would think that usage_request is a reasonable enhancement that we could propose as a JEP and codify in the Jupyter messaging specification, together with a way for kernel to announce that it supports it (or for client to probe if kernel does).

As a short-term solution (beside starting a pre-proposal for a JEP) I would imagine we could ensure that the request is sent at most once (i.e. avoid sending the message again if kernel did not reply).