WebSocket isn't connecting

287 views
Skip to first unread message

Seth Pincock

unread,
Apr 22, 2020, 4:34:43 PM4/22/20
to VPython-users
I am trying to run a VPython animation from within a Jupyter environment—the actual codes are on another shared computer that I connect to remotely through Jupyter.

VPython has worked fine for me in Jupyter in the past, but it was recently updated to VPython 7.6.1. The notebook kernel was also updated to Python 3.5.

When I try to execute my VPython script, it hangs forever. When I interrupt the kernel to diagnose the problem, I see this:

~/.local/lib/python3.5/site-packages/vpython/with_notebook.py in <module>
    151 baseObj.glow = GlowWidget(wsport=__SOCKET_PORT, wsuri='/ws')
    152 while (not wsConnected):
--> 153     time.sleep(0.1)          # wait for websocket to connect
    154 
    155 baseObj.trigger()  # start the trigger ping-pong process

So, it seems to me that the WebSocket connection is failing, so the code waits forever. I'm not really knowledgeable enough to know quite what that means or how to fix it, so any help is appreciated. 

John

unread,
Apr 22, 2020, 5:10:05 PM4/22/20
to VPython-users
Hi

    VPython requires python version 3.5.3 or higher. You mentioned you updated to Python 3.5 so be sure that you are using at least Python 3.5.3 .

John

Seth Pincock

unread,
Apr 23, 2020, 8:05:24 PM4/23/20
to VPython-users
Looks like it's running 3.5.2! I'll have to upgrade it and see if that resolves the issue.

Seth Pincock

unread,
May 7, 2020, 6:42:59 PM5/7/20
to VPython-users
So, I've tried to upgrade to Python 3.5.3. When I run `print(sys.version)` in Jupiter kernel it does say that it is running Python 3.5.3, but VPython is still not working.

 It is the same issue where I can call `from vpython import *` just fine, but when I try to run anything like `box()` the code hangs while waiting for websocket to connect.



On Wednesday, April 22, 2020 at 3:10:05 PM UTC-6, John wrote:

John

unread,
May 8, 2020, 6:13:32 PM5/8/20
to VPython-users
VPython has been tested to connect via a websocket to a remote computer that is running vpython on a JupyterHub or a BInderHub. Here is an example of running vpython in a Jupyter Notebook with vpython running on a remote computer using BinderHub in the cloud. 


You can run each of the vpython demo programs by clicking on the link which will open up a Jupyter Notebook containing the vpython demo program. 

   What is running on the remote computer that you are trying to connect to. Are you using JupyterHub or BinderHub? Also are you using a classic Jupyter Notebook or are you using a jupyterlab notebook. 

   Can you verify that you are using vpython 7.6.1. You can do that with the following code

   from vpython import *
   print(version)


  When I tried installing vpython using Anaconda environment running python 3.5.4 it installed vpython version 7.5.0 and not the latest version of vpython which is 7.6.1.  So I was wondering if the latest vpython 7.6.1 runs on python 3.5.3. I am not able to create an Anaconda environment which runs python 3.5.3 so I can't test vpython on it. 

John

John

unread,
May 8, 2020, 10:53:02 PM5/8/20
to VPython-users
OK I tried the combination of vpython 7.6.1 and python 3.5.3 on a remote host and found that I could run vpython programs with this combination. You can try it on mybinder using this link.

https://mybinder.org/v2/gh/jcoady/py353/master

Click on the link above to launch mybinder running python 3.5.3 and it has vpython 7.6.1 installed. Try running the vpython notebook BinaryStar.ipynb

If the vpython program fails to run then select the menu option in the notebook

    Kernel -> Restart and Clear Output

Then try execute the vpython program again. It should work for you.

This may be all that you need to do to get vpython running in a Jupyter Notebook from your remote host. Just try running the menu option above in your vpython notebook if it fails to run the first time.

     Kernel -> Restart and Clear Output

John

John

unread,
May 9, 2020, 10:27:51 AM5/9/20
to VPython-users
I looked into this problem further and found that is a bug that I have a fix for. I followed the instructions here on how to run a Remote Jupyter Notebook. 


In my case I have 2 Windows machines on my local network and I started a Jupyter Notebook server on one of the machines in no-browser mode and then I established an SSH connection between the two Windows machines and then I launched the notebook in the browser of the other machine. With a small change to the vpython code I was able to establish the websocket connection between the two Windows machines and the vpython program ran properly. One Windows machine acted as the remote Jupyter Notebook server running the python kernel and the other machine was the Jupyter Notebook frontend running in the browser.

If you want to try out the fix yourself you will need to modify the file


in your vpython installation and change line 40 from

url = "ws://localhost:" + port + uri;

to

new_uri += '//' + document.location.host + service_url;
url = new_uri

You will then need to delete the glowcomm.js file in the nbextensions folder on your machine so that it gets overwritten with the new changes that you made from the vpython package. On my Windows machine the file to be deleted is located at

    AppData/Roaming/jupyter/nbextensions/vpython_libraries/glowcomm.js


John
Reply all
Reply to author
Forward
0 new messages