Read ipywidget user value if the main thread is blocked by loop

75 views
Skip to first unread message

Attila Bagoly

unread,
Jul 13, 2016, 9:40:25 AM7/13/16
to Project Jupyter
Hi!

I'm working on interactive interface (using ipywidgets) for a machine learning library in jupyter. I have a function with a big loop (training loop) which blocks the main thread (I can't put this loop to a different thread) and therefore I can't interact with server during the training.


I made a simple example:

from time import sleep
from ipywidgets import widgets
from IPython.display import display


fs
= widgets.FloatSlider(max=100, value=0)
display
(fs)
for i in range(10):
    display
(fs.value)
    sleep
(1)

Here I won't see the change in fs.value until the loop ended. How can I force IPython to synchronize the fs.value in every iteration?

Attila

Hai Nguyen

unread,
Jul 13, 2016, 11:03:07 AM7/13/16
to jup...@googlegroups.com
you can try this

# 1st cell
import ipywidgets

fslider = ipywidgets.FloatSlider(max=10, min=0)
fslider

# 2nd cell
import time

for i in range(8):
    fslider.value = i
    time.sleep(0.2)


Hai

--
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 jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/f0b55a1c-7127-479d-804c-48c041d29b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attila Bagoly

unread,
Jul 13, 2016, 4:02:20 PM7/13/16
to Project Jupyter
In this direction works even if everything is in same cell. But what I need is reading the value in the for loop, and if I changed the value in javascript I want to see it. 

In that example I'm just displaying the value of slider. If you move the slider during the loop, the fs.value won't change. This is my problem. 
Reply all
Reply to author
Forward
0 new messages