Hi --

I'm trying to get values from Javascript to a running Notebook ... think of 
the values as telemetry data coming from the client browser/PC. 

The idea is for the Notebook to trigger the Javascript in one cell and then 
chew on the data in Python (3.7) in another cell.

This works when I single step the cells, but not when I run all cells in 
one swipe. 

I think the reason is that the kernel execute/shell queue is serviced only 
once the kernel goes idle. When I'm single stepping through the cells, 
kernel idle would occur at the end of each cell. But when I'm running all 
cells, idle doesn't occur until after I needed the value. Bad news.

Here are my three cells (as a toy example, actual notebook file attached):

*#1:*







*from IPython.display import HTMLjavascript = f'''<script 
type="text/Javascript">var my_var = 10</script>'''HTML(javascript)*


*#2:*






*javascript = f'''<script 
type="text/Javascript">IPython.notebook.kernel.execute("py_var = " + 
my_var)my_var = my_var + 1</script>'''HTML(javascript)*


*#3:*
*print(py_var)*

To see this, run #1, followed by #2, and followed by #3. Rightly, the 
output of #3 would be *10*. If I run #2 and then #3 again, I would 
(rightly) get *11*.

Then, if I run "#2 and below", the output of #3 is *still **11*, even 
though my_var actually held *12* and there was a pending 'py_var=12' in the 
execute queue.

This is wrong. I really hope for the execute queue to be serviced before #3 
runs ... not OK to single step through cells.

Is there a way to get the execute queue serviced between cells even when 
running "#2 and below"?

I have gone through kernel services code 
(https://github.com/jupyter/notebook/blob/master/notebook/static/services/kernels/kernel.js)
 
and see how the execute() works from the client side. I think I'm really 
asking for explicit flushing of the shell channel at the server side ... 
not so obvious where to look for this.

Is there any way to finesse this execute queue processing?

Alternatively, is there a custom widget protocol that applies? 

Alternatively, should I be creating my own web socket and protocol for 
this??

(I well understand how the shell protocol servicing strategy may not be 
suited to this, but I'm not sure where I should be going next.)

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/8bc7dcae-d6c9-409f-a3b5-457d9e815554o%40googlegroups.com.

Attachment: Toy Example Execute Queue.ipynb
Description: Binary data

Reply via email to