holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 402 forks source link

Javascript Errors when setting Extension in Jupyter Notebook #5699

Open MikeB2019x opened 1 year ago

MikeB2019x commented 1 year ago

ALL software version info

MacOS: Ventura 13.3.1 holoviews: 1.15.4 bokeh: 2.4.3 matplotlib: 3.7.1 matplotlib-inline: 0.1.6 python: 3.10.10 jupyter notebook server: 6.5.4

Description of expected behavior and the observed behavior

After several successful plots, rendering stops completely in a Jupyter Notebook. The behaviour seems intermittent. The following simple experiment isolates the general behaviour.

In a completely new jupyter notebook, I execute three cells in order as follows: image

The code is doing nothing but an import and setting extensions. The javascript console shows:

Kernel: kernel_ready (c9a6c11a-3f38-4a83-8f7f-b4eb1b310723)
kernel_exec_on_cell.js?v=20230426164150:340 [autopep8] restarting for new kernel_ready.Kernel event
outputarea.js:774 SyntaxError: Unexpected token ')'
    at OutputArea.append_javascript (outputarea.js:772:1)
    at OutputArea.append_mime_type (outputarea.js:710:1)
    at OutputArea.append_display_data (outputarea.js:671:1)
    at OutputArea.append_output (outputarea.js:345:1)
    at OutputArea.handle_output (outputarea.js:256:1)
    at output (codecell.js:399:1)
    at Kernel._handle_output_message (kernel.js:1199:1)
    at i (jquery.min.js:2:1)
    at Kernel._handle_iopub_message (kernel.js:1239:1)
    at Kernel._finish_ws_message (kernel.js:1018:1)
outputarea.js:774 SyntaxError: Identifier 'r' has already been declared
    at OutputArea.append_javascript (outputarea.js:772:1)
    at OutputArea.append_mime_type (outputarea.js:710:1)
    at OutputArea.append_display_data (outputarea.js:671:1)
    at OutputArea.append_output (outputarea.js:345:1)
    at OutputArea.handle_output (outputarea.js:256:1)
    at output (codecell.js:399:1)
    at Kernel._handle_output_message (kernel.js:1199:1)
    at i (jquery.min.js:2:1)
    at Kernel._handle_iopub_message (kernel.js:1239:1)
    at Kernel._finish_ws_message (kernel.js:1018:1)

Important: If I go back and run the cells again ... no errors.

The challenge is the behaviour shows up intermittently in that graphical output will be fine for several cells, then stop working. Clearing the fault and getting expected behaviour again means forcing re-import of holoviews and/or resetting the extension until the JS error no longer appears and/or restarting the kernel.

I'm not sure if this is a Holoviews challenge or a Jupyter challenge b/c when running in my working notebook I sometimes get this JS console error:

Comm promise not found for comm id hv-extension-comm
CommManager.comm_msg @ comm.js:127
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1009
i @ jquery.min.js:2
VM104:343 [bokeh] setting log level to: 'info'
comm.js:127 Comm promise not found for comm id hv-extension-comm
CommManager.comm_msg @ comm.js:127
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1009
i @ jquery.min.js:2
kernel.js:466 WebSocket connection to 'ws://localhost:5533/api/kernels/0b4d3d22-ed9d-4247-935e-8ad92b358d59/channels?session_id=05bfc24a61a24d2e959bd10f2acd0b69' failed: Invalid frame header
Kernel.start_channels @ kernel.js:466
kernel.js:107 Kernel: kernel_disconnected (0b4d3d22-ed9d-4247-935e-8ad92b358d59)
hoxbro commented 1 year ago

I can't recreate the issue: image

Can you create a clean environment and see if the problem still happens in a new notebook?

MikeB2019x commented 1 year ago

I've done it repeatedly these past few days on a fresh notebook (w/extensions disabled). I will get one of three behaviours:

  1. no error (but in an active 'real' notebook an error will crop up later)
  2. JS error of some kind (latest error variant below)
  3. cell hangs and does not complete execution

Because of the intermittent behaviour and the frequency of "unexpected identifier xxx" messages, it's like the UI is sometimes receiving partial/truncated data/message?

SyntaxError: Unexpected identifier 'incompatible'
    at OutputArea.append_javascript (outputarea.js:772:1)
    at OutputArea.append_mime_type (outputarea.js:710:1)
    at OutputArea.append_display_data (outputarea.js:671:1)
    at OutputArea.append_output (outputarea.js:345:1)
    at OutputArea.handle_output (outputarea.js:256:1)
    at output (codecell.js:399:1)
    at Kernel._handle_output_message (kernel.js:1199:1)
    at i (jquery.min.js:2:1)
    at Kernel._handle_iopub_message (kernel.js:1239:1)
    at Kernel._finish_ws_message (kernel.js:1018:1)
hoxbro commented 1 year ago

Did you try it in a clean environment? And can you paste your pip list / conda list?

MikeB2019x commented 1 year ago

Yes, clean environment meaning new notebook w/just two cells as illustrated above. pip list:

Package                           Version
--------------------------------- ---------
anyio                             3.6.2
appnope                           0.1.3
argon2-cffi                       21.3.0
argon2-cffi-bindings              21.2.0
asttokens                         2.2.1
attrs                             23.1.0
autopep8                          2.0.2
Babel                             2.12.1
backcall                          0.2.0
beautifulsoup4                    4.12.2
bleach                            6.0.0
blinker                           1.6.2
bokeh                             2.4.3
Brotli                            1.0.9
certifi                           2022.12.7
cffi                              1.15.1
charset-normalizer                3.1.0
click                             8.1.3
colorcet                          3.0.1
comm                              0.1.3
contourpy                         1.0.7
cycler                            0.11.0
dash                              2.6.2
dash-bootstrap-components         1.2.1
dash-core-components              2.0.0
dash-cytoscape                    0.3.0
dash-html-components              2.0.0
dash-table                        5.0.0
debugpy                           1.6.7
decorator                         5.1.1
defusedxml                        0.7.1
executing                         1.2.0
Faker                             16.6.1
fastjsonschema                    2.16.3
Flask                             2.3.1
Flask-Compress                    1.13
fonttools                         4.39.3
gensim                            4.3.1
holoviews                         1.15.4
idna                              3.4
interchange                       2021.0.4
ipykernel                         6.22.0
ipython                           8.12.0
ipython-genutils                  0.2.0
ipywidgets                        8.0.6
itsdangerous                      2.1.2
jedi                              0.18.2
Jinja2                            3.1.2
joblib                            1.2.0
json5                             0.9.11
jsonschema                        4.17.3
jupyter_client                    8.2.0
jupyter-contrib-core              0.4.2
jupyter-contrib-nbextensions      0.7.0
jupyter_core                      5.3.0
jupyter-highlight-selected-word   0.2.0
jupyter-nbextensions-configurator 0.6.1
jupyter-server                    1.24.0
jupyterlab                        3.0.7
jupyterlab-pygments               0.2.2
jupyterlab_server                 2.22.1
jupyterlab-widgets                3.0.7
kiwisolver                        1.4.4
llvmlite                          0.39.1
lxml                              4.9.2
Markdown                          3.4.3
MarkupSafe                        2.1.2
matplotlib                        3.7.1
matplotlib-inline                 0.1.6
mistune                           2.0.5
monotonic                         1.6
nbclassic                         0.5.5
nbclient                          0.7.4
nbconvert                         7.3.1
nbformat                          5.8.0
neo4j                             5.0.1
nest-asyncio                      1.5.6
networkx                          2.8.7
node2vec                          0.4.6
notebook                          6.5.4
notebook_shim                     0.2.3
numba                             0.56.4
numpy                             1.23.3
packaging                         23.1
pandas                            1.5.0
pandocfilters                     1.5.0
panel                             0.14.4
pansi                             2020.7.3
param                             1.13.0
parso                             0.8.3
pexpect                           4.8.0
pickleshare                       0.7.5
Pillow                            9.5.0
pip                               23.1.2
platformdirs                      3.4.0
plotly                            5.10.0
prometheus-client                 0.16.0
prompt-toolkit                    3.0.38
psutil                            5.9.5
ptyprocess                        0.7.0
pure-eval                         0.2.2
py2neo                            2021.2.3
pycodestyle                       2.10.0
pycparser                         2.21
pyct                              0.5.0
Pygments                          2.15.1
pynndescent                       0.5.10
pyparsing                         3.0.9
pyrsistent                        0.19.3
python-dateutil                   2.8.2
python-dotenv                     0.21.0
pytz                              2023.3
pyviz-comms                       2.2.1
PyYAML                            6.0
pyzmq                             25.0.2
requests                          2.29.0
scikit-learn                      1.1.2
scipy                             1.10.1
Send2Trash                        1.8.0
setuptools                        67.7.2
six                               1.16.0
smart-open                        6.3.0
sniffio                           1.3.0
soupsieve                         2.4.1
stack-data                        0.6.2
tenacity                          8.2.2
terminado                         0.17.1
threadpoolctl                     3.1.0
tinycss2                          1.2.1
tomli                             2.0.1
torch                             1.12.1
torch-cluster                     1.6.0
torch-geometric                   2.0.4
torch-scatter                     2.0.9
torch-sparse                      0.6.14
torch-spline-conv                 1.2.1
tornado                           6.3.1
tqdm                              4.65.0
traitlets                         5.9.0
typing_extensions                 4.5.0
umap-learn                        0.5.3
urllib3                           1.26.15
wcwidth                           0.2.6
webencodings                      0.5.1
websocket-client                  1.5.1
Werkzeug                          2.3.0
wheel                             0.40.0
widgetsnbextension                4.0.7
xgboost                           1.7.5
hoxbro commented 1 year ago

Can you create a new environment with only a notebook and holoviews (or at least without torch).

MikeB2019x commented 1 year ago

Getting error below in new env (list below). If I run the cell again I may get another random error eg. Unexpected identifier 'SelectEditorView', Unexpected identifier 'a' (see below), etc. but eventually the extension loads correctly. A bit of searching finds refs to tornado and panel packages when there's problems in Jupyter rendering but no proposed solution has worked for me.

First error.

Kernel: kernel_connected (736ee564-d5c6-4954-beee-46a95224941f)
kernel.js:107 Kernel: kernel_ready (736ee564-d5c6-4954-beee-46a95224941f)
kernel_exec_on_cell.js?v=20230501095044:340 [autopep8] restarting for new kernel_ready.Kernel event
outputarea.js:774 SyntaxError: Unexpected token ')'
    at OutputArea.append_javascript (outputarea.js:772:1)
    at OutputArea.append_mime_type (outputarea.js:710:1)
    at OutputArea.append_display_data (outputarea.js:671:1)
    at OutputArea.append_output (outputarea.js:345:1)
    at OutputArea.handle_output (outputarea.js:256:1)
    at output (codecell.js:399:1)
    at Kernel._handle_output_message (kernel.js:1199:1)
    at i (jquery.min.js:2:1)
    at Kernel._handle_iopub_message (kernel.js:1239:1)
    at Kernel._finish_ws_message (kernel.js:1018:1)

Env package list:

# Name                    Version                   Build  Channel
anyio                     3.6.2                    pypi_0    pypi
appnope                   0.1.3                    pypi_0    pypi
argon2-cffi               21.3.0                   pypi_0    pypi
argon2-cffi-bindings      21.2.0                   pypi_0    pypi
arrow                     1.2.3                    pypi_0    pypi
asttokens                 2.2.1                    pypi_0    pypi
attrs                     23.1.0                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
beautifulsoup4            4.12.2                   pypi_0    pypi
bleach                    6.0.0              pyhd8ed1ab_0    conda-forge
bokeh                     2.4.3              pyhd8ed1ab_3    conda-forge
brotli                    1.0.9                hb7f2c08_8    conda-forge
brotli-bin                1.0.9                hb7f2c08_8    conda-forge
brotlipy                  0.7.0           py310h90acd4f_1005    conda-forge
bzip2                     1.0.8                h0d85af4_4    conda-forge
ca-certificates           2022.12.7            h033912b_0    conda-forge
certifi                   2022.12.7          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310ha78151a_3    conda-forge
charset-normalizer        3.1.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
colorcet                  3.0.1              pyhd8ed1ab_0    conda-forge
comm                      0.1.3                    pypi_0    pypi
contourpy                 1.0.7           py310ha23aa8a_0    conda-forge
cryptography              40.0.2          py310hdd0c95c_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.7                    pypi_0    pypi
decorator                 5.1.1                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
executing                 1.2.0                    pypi_0    pypi
fastjsonschema            2.16.3                   pypi_0    pypi
fonttools                 4.39.3          py310h90acd4f_0    conda-forge
fqdn                      1.5.1                    pypi_0    pypi
freetype                  2.12.1               h3f81eb7_1    conda-forge
holoviews                 1.15.4             pyhd8ed1ab_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
importlib-metadata        6.6.0              pyha770c72_0    conda-forge
ipykernel                 6.22.0                   pypi_0    pypi
ipython                   8.13.1                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
isoduration               20.11.0                  pypi_0    pypi
jedi                      0.18.2                   pypi_0    pypi
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jsonpointer               2.3                      pypi_0    pypi
jsonschema                4.17.3                   pypi_0    pypi
jupyter-client            8.2.0                    pypi_0    pypi
jupyter-core              5.3.0                    pypi_0    pypi
jupyter-events            0.6.3                    pypi_0    pypi
jupyter-server            2.5.0                    pypi_0    pypi
jupyter-server-terminals  0.4.4                    pypi_0    pypi
jupyterlab-pygments       0.2.2                    pypi_0    pypi
kiwisolver                1.4.4           py310ha23aa8a_1    conda-forge
lcms2                     2.15                 h2dcdeff_1    conda-forge
lerc                      4.0.0                hb486fe8_0    conda-forge
libblas                   3.9.0           16_osx64_openblas    conda-forge
libbrotlicommon           1.0.9                hb7f2c08_8    conda-forge
libbrotlidec              1.0.9                hb7f2c08_8    conda-forge
libbrotlienc              1.0.9                hb7f2c08_8    conda-forge
libcblas                  3.9.0           16_osx64_openblas    conda-forge
libcxx                    16.0.2               hd57cbcb_0    conda-forge
libdeflate                1.18                 hac1461d_0    conda-forge
libffi                    3.4.2                h0d85af4_5    conda-forge
libgfortran               5.0.0           11_3_0_h97931a8_31    conda-forge
libgfortran5              12.2.0              he409387_31    conda-forge
libjpeg-turbo             2.1.5.1              hb7f2c08_0    conda-forge
liblapack                 3.9.0           16_osx64_openblas    conda-forge
libopenblas               0.3.21          openmp_h429af6e_3    conda-forge
libpng                    1.6.39               ha978bb4_0    conda-forge
libsqlite                 3.40.0               ha978bb4_1    conda-forge
libtiff                   4.5.0                hedf67fa_6    conda-forge
libwebp-base              1.3.0                hb7f2c08_0    conda-forge
libxcb                    1.13              h0d85af4_1004    conda-forge
libzlib                   1.2.13               hfd90126_4    conda-forge
llvm-openmp               16.0.2               hff08bdf_0    conda-forge
markdown                  3.4.3              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.2           py310h90acd4f_0    conda-forge
matplotlib-base           3.7.1           py310he725631_0    conda-forge
matplotlib-inline         0.1.6                    pypi_0    pypi
mistune                   2.0.5                    pypi_0    pypi
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
nbclassic                 0.5.6                    pypi_0    pypi
nbclient                  0.7.4                    pypi_0    pypi
nbconvert                 7.3.1                    pypi_0    pypi
nbformat                  5.8.0                    pypi_0    pypi
ncurses                   6.3                  h96cf925_1    conda-forge
nest-asyncio              1.5.6                    pypi_0    pypi
notebook                  6.5.4                    pypi_0    pypi
notebook-shim             0.2.3                    pypi_0    pypi
numpy                     1.24.3          py310h7451ae0_0    conda-forge
openjpeg                  2.5.0                h13ac156_2    conda-forge
openssl                   3.1.0                h8a1eda9_2    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandas                    2.0.1           py310h5e4fcda_0    conda-forge
pandocfilters             1.5.0                    pypi_0    pypi
panel                     0.14.4             pyhd8ed1ab_0    conda-forge
param                     1.13.0             pyh1a96a4e_0    conda-forge
parso                     0.8.3                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    9.5.0           py310h6b2f720_0    conda-forge
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
platformdirs              3.5.0                    pypi_0    pypi
prometheus-client         0.16.0                   pypi_0    pypi
prompt-toolkit            3.0.38                   pypi_0    pypi
psutil                    5.9.5                    pypi_0    pypi
pthread-stubs             0.4               hc929b4f_1001    conda-forge
ptyprocess                0.7.0                    pypi_0    pypi
pure-eval                 0.2.2                    pypi_0    pypi
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyct                      0.4.6                      py_0    conda-forge
pyct-core                 0.4.6                      py_0    conda-forge
pygments                  2.15.1                   pypi_0    pypi
pyopenssl                 23.1.1             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyrsistent                0.19.3                   pypi_0    pypi
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.10.10         he7542f4_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-json-logger        2.0.7                    pypi_0    pypi
python-tzdata             2023.3             pyhd8ed1ab_0    conda-forge
python_abi                3.10                    3_cp310    conda-forge
pytz                      2023.3             pyhd8ed1ab_0    conda-forge
pyviz_comms               2.2.1              pyhd8ed1ab_1    conda-forge
pyyaml                    6.0             py310h90acd4f_5    conda-forge
pyzmq                     25.0.2                   pypi_0    pypi
readline                  8.2                  h9e318b2_1    conda-forge
requests                  2.29.0             pyhd8ed1ab_0    conda-forge
rfc3339-validator         0.1.4                    pypi_0    pypi
rfc3986-validator         0.1.1                    pypi_0    pypi
send2trash                1.8.2                    pypi_0    pypi
setuptools                67.7.2             pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sniffio                   1.3.0                    pypi_0    pypi
soupsieve                 2.4.1                    pypi_0    pypi
stack-data                0.6.2                    pypi_0    pypi
terminado                 0.17.1                   pypi_0    pypi
tinycss2                  1.2.1                    pypi_0    pypi
tk                        8.6.12               h5dbffcc_0    conda-forge
tornado                   6.3.1                    pypi_0    pypi
tqdm                      4.65.0             pyhd8ed1ab_1    conda-forge
traitlets                 5.9.0                    pypi_0    pypi
typing_extensions         4.5.0              pyha770c72_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
unicodedata2              15.0.0          py310h90acd4f_0    conda-forge
uri-template              1.2.0                    pypi_0    pypi
urllib3                   1.26.15            pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.6                    pypi_0    pypi
webcolors                 1.13                     pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
websocket-client          1.5.1                    pypi_0    pypi
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.9                h35c211d_0    conda-forge
xorg-libxdmcp             1.1.3                h35c211d_0    conda-forge
xz                        5.2.6                h775f41a_0    conda-forge
yaml                      0.2.5                h0d85af4_2    conda-forge
zipp                      3.15.0             pyhd8ed1ab_0    conda-forge
zstd                      1.5.2                hbc0c0cd_6    conda-forge

Random error: image

hoxbro commented 1 year ago

It is generally not advised to mix PyPi and conda-forge (though, I don't think this is the problem).

Can you give me the output of conda env export? This will make it easier for me to create the environment.

You could try running dev releases of panel + holoviews by running conda install -c pyviz/label/dev panel holoviews and see if the error is still there.

You can also see if there is some weird setting in ~/.ipython folder by renaming and starting the notebook again.

MikeB2019x commented 1 year ago

Voila. Tnx for the assist.

new_env.txt

MikeB2019x commented 1 year ago

This error. Also happened after renaming: image

This env: clean_env.txt

hoxbro commented 1 year ago

Thank you. I could recreate the problem. It seems to be coming from panel.io.load_notebook.

image

@philippjfr, should I move this to Panel?

MikeB2019x commented 1 year ago

In case it helps: if this error crops up you have to reset the kernel.

Comm promise not found for comm id hv-extension-comm
CommManager.comm_msg @ comm.js:127
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
hoxbro commented 1 year ago

Can you try hv.extension("bokeh", inline=False)?

I'm also getting this error in the jupyter logs:

E 11:04:14.585 NotebookApp] Uncaught exception, closing connection.
    Traceback (most recent call last):
      File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 695, in _handle_events
        self._handle_write()
      File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 965, in _handle_write
        self._write_buffer.advance(num_bytes)
      File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 182, in advance
        assert 0 < size <= self._size
    AssertionError
Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
  File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 192, in _handle_events
    handler_func(fileobj, events)
  File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 695, in _handle_events
    self._handle_write()
  File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 965, in _handle_write
    self._write_buffer.advance(num_bytes)
  File "/Users/shh/miniconda3/envs/tmp55/lib/python3.10/site-packages/tornado/iostream.py", line 182, in advance
    assert 0 < size <= self._size
AssertionError
MikeB2019x commented 1 year ago

Let me preface by saying it seems to be more stable (subjectively) but ... I tried your suggestion in a 2 cell notebook: first cell did imports, second executed hv.extension.

If it ran successfully sometimes I got in the following in the js console:

    at inline_js (eval at append_javascript (outputarea.js:772:1), <anonymous>:143:13)
    at run_inline_js (eval at append_javascript (outputarea.js:772:1), <anonymous>:151:22)
    at eval (eval at append_javascript (outputarea.js:772:1), <anonymous>:166:7)
    at eval (eval at append_javascript (outputarea.js:772:1), <anonymous>:22:11)
    at Array.forEach (<anonymous>)
    at run_callbacks (eval at append_javascript (outputarea.js:772:1), <anonymous>:20:36)
    at on_load (eval at append_javascript (outputarea.js:772:1), <anonymous>:50:9)
    at eval (eval at append_javascript (outputarea.js:772:1), <anonymous>:75:2)
    at Object.execCb (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:1693:33)
    at Module.check (require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593:881:51)

If I repeatedly run the second cell with the inline argument I will eventually get. If I get this in working notebook, rendering becomes intermittent ie. if I keep running a cell with a plot output I may get a render:

mm.js:127 Comm promise not found for comm id hv-extension-comm
CommManager.comm_msg @ comm.js:127
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1009
i @ jquery.min.js:2

If I repeatedly run the second cell w/o the inline argument I will eventually get:

Kernel.start_channels @ kernel.js:466
kernel.js:107 Kernel: kernel_disconnected (0562a601-6703-4d0b-b67b-eaa4848ef955)
kernel.js:547 WebSocket connection failed:  ws://localhost:8897/api/kernels/0562a601-6703-4d0b-b67b-eaa4848ef955 true
kernel.js:565 Connection lost, reconnecting in 1 seconds.
kernel.js:494 WebSocket closed unexpectedly CloseEvent {isTrusted: true, wasClean: false, code: 1006, reason: '', type: 'close', …}
kernel.js:107 Kernel: kernel_reconnecting (0562a601-6703-4d0b-b67b-eaa4848ef955)
kernel.js:464 Starting WebSockets: ws://localhost:8897/api/kernels/0562a601-6703-4d0b-b67b-eaa4848ef955
kernel.js:107 Kernel: kernel_connected (0562a601-6703-4d0b-b67b-eaa4848ef955)
kernel.js:107 Kernel: kernel_ready (0562a601-6703-4d0b-b67b-eaa4848ef955)
kernel_exec_on_cell.js?v=20230529164045:340 [autopep8] restarting for new kernel_ready.Kernel event
comm.js:127 Comm promise not found for comm id hv-extension-comm
CommManager.comm_msg @ comm.js:127
i @ jquery.min.js:2
Kernel._handle_iopub_message @ kernel.js:1239
Kernel._finish_ws_message @ kernel.js:1018
(anonymous) @ kernel.js:1009
Promise.then (async)
Kernel._handle_ws_message @ kernel.js:1009
i @ jquery.min.js:2
outputarea.js:774 SyntaxError: missing ) after argument list
    at OutputArea.append_javascript (outputarea.js:772:1)
    at OutputArea.append_mime_type (outputarea.js:710:1)
    at OutputArea.append_display_data (outputarea.js:671:1)
    at OutputArea.append_output (outputarea.js:345:1)
    at OutputArea.handle_output (outputarea.js:256:1)
    at output (codecell.js:399:1)
    at Kernel._handle_output_message (kernel.js:1199:1)
    at i (jquery.min.js:2:1)
    at Kernel._handle_iopub_message (kernel.js:1239:1)
    at Kernel._finish_ws_message (kernel.js:1018:1)
sandhujasmine commented 1 year ago

I've also run into this issue and have found that pinning tornado to 6.1 seems to fix it. I saw similar error pop up on this jupyter discourse and tried the proposed solution. In my manual testing, this seems to fix it.

Creating the following environment without pinning tornado almost always gives the javascript error and also the tornado AssertionError when I restart the kernel. It also does not always render the plots even though the extensions seem to load if you run the cell again after you get the javascript syntax error.

conda create -n hv_test holoviews bokeh notebook
SyntaxError and AssertionError on kernel restart using above env: ![image](https://github.com/holoviz/holoviews/assets/359129/826aa562-49be-49c4-9fdc-6d22ba56aadc) __AssertionError exception in tornado when kernel is restarted__ Update: Adding the correct AssertionError ``` [E 15:40:13.835 NotebookApp] Uncaught exception, closing connection. Traceback (most recent call last): File "/Users/jasmine/miniconda3/envs/hv_test/lib/python3.11/site-packages/tornado/iostream.py", line 702, in _handle_events self._handle_write() File "/Users/jasmine/miniconda3/envs/hv_test/lib/python3.11/site-packages/tornado/iostream.py", line 976, in _handle_write self._write_buffer.advance(num_bytes) File "/Users/jasmine/miniconda3/envs/hv_test/lib/python3.11/site-packages/tornado/iostream.py", line 182, in advance assert 0 < size <= self._size AssertionError [W 15:40:13.839 NotebookApp] zmq message arrived on closed channel ```

Pinning the tornado version seems to fix it:

conda create -n hv_test holoviews bokeh notebook tornado=6.1
The holoviews example is just running part of the `Tap` example (see below): ``` import pandas as pd import numpy as np import holoviews as hv from holoviews import opts hv.extension('bokeh', width=90) # Create an empty Points element points = hv.Points([]) # Create the Tap stream with the points element as the source # We set the x and y here with starting values stream = hv.streams.Tap(source=points, x=np.nan, y=np.nan) # Create a callback for a dynamic map def location(x, y): """Create an empty plot with a changing label""" return hv.Points([], label='x: %0.3f, y: %0.3f' % (x, y)) # Connect the Tap stream to the tap_histogram callback tap_dmap = hv.DynamicMap(location, streams=[stream]) # Overlay the Points element (which is linked to the tap stream) with the location plot points * tap_dmap ``` ![image](https://github.com/holoviz/holoviews/assets/359129/6adc8326-fc19-4ae8-82b7-70be23beb1a1)
hoxbro commented 1 year ago

Thank you, @sandhujasmine. Looking at a linked issue in the thread you linked https://github.com/jupyter/notebook/issues/6721#issuecomment-1445187389, it seems to be related to changes made in jupyter_client 8+. Tornado 6.1 pulls down jupyter_client<8, which is why the problem is not there which that Tornado version. Can you try creating a new environment, with no pin on Tornado and pin jupyter_client<8, to confirm this?

sandhujasmine commented 1 year ago

@Hoxbro - I manually tested this and it seems to work with newer tornado but older jupyter_client as you suggested.

% conda list 'tornado|jupyter_client'
# packages in environment at /Users/jasmine/miniconda3/envs/hv_test:
#
# Name                    Version                   Build  Channel
jupyter_client            7.4.9           py311hca03da5_0    defaults
tornado                   6.2             py311h80987f9_0    defaults