Threading or not

42 views
Skip to first unread message

Bruce Sherwood

unread,
Sep 28, 2016, 1:49:59 AM9/28/16
to Project Jupyter
Since I've posted ill-formed questions several times I'd like to pay patient readers back by describing a successful answer to something that might affect others.

In Jupyter VPython (see vpython.org) data is sent from a Python program to a JavaScript program and is processed by the GlowScript WebGL library to display 3D animations in the notebook. There are restrictions on sending data from a Python thread, and I even found a disastrous case where early data sent from within a Python thread arrived in the browser after later data sent from outside that thread, yet there seemed no way to avoid the necessity of a thread that would interrupt and send data about 30 times per second.

A robust solution turned out to be the following: The JavaScript program sends an event to Python, which calls a Python program that sends data (if any) to the JavaScript program and in all cases sends a message requesting that the JavaScript program set a timer to send Python another event 1/30th of a second from now. In that way there is no thread in the Python program, so data transmissions are not sent from within a Python thread. 

One might think that the JavaScript program could set an interval timer to send the wakeup message regularly to Python. However, when I tried that scheme it turned out to be very difficult to rerun or kill a program. Apparently killing the kernel doesn't stop JavasScript timeouts. Doing the full roundtrip handshake assures that the JavaScript program will not keep running if the Python program is killed.

Lawrence D’Oliveiro

unread,
Sep 28, 2016, 4:21:35 AM9/28/16
to Project Jupyter
On Wednesday, September 28, 2016 at 6:49:59 PM UTC+13, Bruce Sherwood wrote:
Apparently killing the kernel doesn't stop JavasScript timeouts.


JavaScript runs entirely in the browser.

Bruce Sherwood

unread,
Sep 28, 2016, 10:56:00 AM9/28/16
to jup...@googlegroups.com
Certainly, JavaScript runs in the browser, but I think I had the naive notion that having started the JavaScript from Python there would be some mechanism built into the Juptyer machinery that would/could stop the client code. Is there such a mechanism?

Thomas Kluyver

unread,
Sep 28, 2016, 11:05:12 AM9/28/16
to Project Jupyter
On 28 September 2016 at 15:55, Bruce Sherwood <bruce.s...@gmail.com> wrote:
Certainly, JavaScript runs in the browser, but I think I had the naive notion that having started the JavaScript from Python there would be some mechanism built into the Juptyer machinery that would/could stop the client code. Is there such a mechanism?

There is not!
Reply all
Reply to author
Forward
0 new messages