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

Rewrite server extension to run Panel applications in kernels #3763

Merged
merged 21 commits into from Aug 19, 2022

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Aug 17, 2022

This PR reimplements the panel preview server extension in its entirety to execute Panel applications in custom kernels. It does this by querying the notebook for its kernel spec and then requesting a kernel from Jupyter. In this kernel it executes the following:

from panel.io.jupyter_server_extension import PanelExecutor
executor = PanelExecutor('{{ path }}', '{{ token }}', '{{ root_url }}')
executor.render()

Internally the PanelExecutor creates a bokeh ServerSession and connects it to a Jupyter Comm. The PanelHandler will then serve the result of executor.render() and a request to open a WebSocket will be sent to the PanelWSHandler. This in turns forwards any messages it receives via the kernel.shell_channel to the Comm. This way we proxy any WS messages being sent to and from the server to the kernel.

The major benefit of this is:

  • Panel preview now actually uses the appropriate kernel (and therefore environment) that it was intended for.

Drawbacks:

  • Spinning up a kernel per session is expensive (we may be able to fix this by keeping only one kernel per kernelspec).

ToDo

@codecov
Copy link

codecov bot commented Aug 17, 2022

Codecov Report

Merging #3763 (1f5b97a) into master (e1d3bfc) will decrease coverage by 0.50%.
The diff coverage is 16.11%.

@@            Coverage Diff             @@
##           master    #3763      +/-   ##
==========================================
- Coverage   84.21%   83.70%   -0.51%     
==========================================
  Files         213      214       +1     
  Lines       31016    31267     +251     
==========================================
+ Hits        26121    26173      +52     
- Misses       4895     5094     +199     
Flag Coverage Δ
ui-tests 33.89% <16.31%> (-0.10%) ⬇️
unitexamples-tests 76.56% <5.67%> (-0.57%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
panel/auth.py 39.34% <0.00%> (ø)
panel/io/jupyter_server_extension.py 0.00% <0.00%> (ø)
panel/tests/conftest.py 94.32% <86.66%> (-1.41%) ⬇️
panel/io/resources.py 87.10% <100.00%> (ø)
panel/io/state.py 69.16% <100.00%> (+0.06%) ⬆️
panel/tests/ui/io/test_jupyter_server_extension.py 100.00% <100.00%> (ø)
panel/util.py 86.41% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@MarcSkovMadsen
Copy link
Collaborator

I can't see there is a high probability of someone spinning up lots of kernels unless they have Jupyter lab for ever running.

But maybe in a Jupyter Hub environment this could become an issue?

Our JupyterHub closes the session/ server after 1 hour of inactivity though.

@philippjfr philippjfr merged commit 9748d22 into master Aug 19, 2022
@philippjfr philippjfr deleted the run_server_apps_in_kernel branch August 19, 2022 20:03
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

Successfully merging this pull request may close these issues.

None yet

2 participants