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

Connect to existing kernel on subsequent accesses #515

Open
Jul3k opened this issue Jan 14, 2020 · 10 comments
Open

Connect to existing kernel on subsequent accesses #515

Jul3k opened this issue Jan 14, 2020 · 10 comments

Comments

@Jul3k
Copy link

Jul3k commented Jan 14, 2020

Is it possible to configure voila in a way, that it does not run the python code again on subsequent browser accesses but connects to the existing kernel and reloads the widget state?
I have a Notebook containing jupyter widgets that control a C-API, which I can only instantiate once. With JupyterLab and Jupyter Notebook the widget state is saved in the notebook. This allows on a second access where the widgets still interact with the existing kernel. It would be awesome if voila could behave similar.

@timkpaine
Copy link
Member

timkpaine commented Jan 14, 2020

Every time a user connects (including when they revisit the page), a brand new kernel is instantiated. So voila already only runs the python code once.

If instead, you're talking about sharing one kernel amongst multiple users, how would you manage concurrency of widgets? if one person moves a slider, does it have to sync for everyone? What if person A is entitled to access some data that person B is not entitled to, how do you enforce that for everyone? I think the per-user segregation is one of the most valuable features of voila, and not something to be changed.

@Jul3k
Copy link
Author

Jul3k commented Jan 14, 2020

Sorry for the misunderstanding. I don't want to change the default behavior. As you said the python code is executed on every access in a different kernel. It would be nice to have the option to share a kernel among multiple accesses.
As I said this is already possible with default Jupyter Lab and Notebook. The case of propagating changes to each frontend is still an open issue (jupyter-widgets/ipywidgets#1218). In the current implementation the changes are not synced.
The scenario you mention is a bit overkill for me as I would be perfectly happy without synced widgets or a user based access policy.

@Jul3k
Copy link
Author

Jul3k commented Jan 15, 2020

I added a bit of code (<10 lines) to handler.py in order to cache the rendered notebook. This way a kernel is only started once on the first notebook access. On subsequent accesses only the rendered notebook is returned. If someone is interested in this, I am willing to submit a merge request. The behavior could be controlled by a configuration flag --cache-notebooks=True

@jtpio
Copy link
Member

jtpio commented Jan 27, 2020

Another place where connecting to an existing kernel could make sense is for the voila preview in JupyterLab (in a single user setup).

This could be useful especially for debugging a voila dashboard without starting a new kernel on every change. But jupyter-widgets/ipywidgets#1218 would indeed still be relevant, as the changes would not be reflected in the preview panel (IFrame). The preview would then be "another view" of the notebook.

@jtpio
Copy link
Member

jtpio commented Jan 27, 2020

Also related: #95

@Vel-San
Copy link

Vel-San commented Jul 29, 2021

I added a bit of code (<10 lines) to handler.py in order to cache the rendered notebook. This way a kernel is only started once on the first notebook access. On subsequent accesses only the rendered notebook is returned. If someone is interested in this, I am willing to submit a merge request. The behavior could be controlled by a configuration flag --cache-notebooks=True

I'm having the same issue as you.

I have 1 notebook, with multiple users hosted in AWS/ECS. Using the Notebook cells, every widget loads just fine, however, the Voila (used as an extension) is always trying to access old kernel that was running and doesn't know that there's a new kernel being used somehow, and gives me 404 errors "Kernel doesn't exist". The only way to bypass this is to refresh the page with cache clearing (e.g. Cntrl + Shift + R) then Voila loads fine.

Can you please tell me if you've found a proper way to fix this?

@ianhi
Copy link

ianhi commented Feb 15, 2022

now that jupyter-widgets/ipywidgets#3195 has been fixed can this be looked at again?

I'd also very much like this! In particular for the use case of controlling a physical device (e.g. arduino) remotely. ipywidgets is by far the easiest way to create browser based a gui for somethign like this. So it would be very exciting to be able to (without any webdev knowledge) easily make a nice GUI that can be controlled remotely. Presuming that jupyter server could manage password access for me then I think there would be an enormous number opportunities in science labs (and home DIY things) for using something like this. However, in those cases there can only ever be one kernel that is connected to the device at a time so starting a new kernel on each connection won't work.

@jtpio are there other concerns to be dealt with before attempting to implement something like this?

@maartenbreddels
Copy link
Member

maartenbreddels commented Feb 15, 2022 via email

@mariobuikhuizen
Copy link
Member

This is meant as a way to show a widget or composition of widgets in a separate browser window/tab (for the same user): https://github.com/mariobuikhuizen/ipypopout, but it may serve as an example on how to connect to an existing kernel when you know the kernel-id. (The current version still has a workaround that can be removed if jupyter-widgets/ipywidgets#3195 is used)

But in the case of @ianhi I think you would want to control having a single kernel from the server.

@kno10
Copy link

kno10 commented Apr 22, 2024

This would be very useful, in particular when certain resources (e.g., GPUs) are limited.
If you reload the page, you have to kill and restart voila to free the GPU.

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

No branches or pull requests

8 participants