Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to block execution until Jupyter widget's value has been updated #7126

Closed
link89 opened this issue Oct 26, 2023 · 1 comment
Closed
Labels
bug status:Needs Triage Applied to issues that need triage

Comments

@link89
Copy link

link89 commented Oct 26, 2023

Given the following code:

from ipywidgets import IntsInput
from IPython.display import display

in_value = IntsInput(description="value")
before = in_value.value
print('before': before)
display(in_value)

while before == in_value.value:
    ...  # blocking until value is changed

print('after', in_value.value)

Obviously, the loop will blocking forever as in_value.value won't be evaluated again. Is there any way to make it work as simple as possible?

It looks like not possible as the observer is running on the main thread. Thus the following method also not work.

from ipywidgets import IntsInput
from IPython.display import display
from queue import Queue
import threading
import time

q = Queue()

widget = IntsInput()
display(widget)
def getvalue(change):
    q.put(change.new)
    widget.unobserve(getvalue, 'value')
widget.observe(getvalue, 'value')

print(q.get())
@link89 link89 added bug status:Needs Triage Applied to issues that need triage labels Oct 26, 2023
@RRosio
Copy link
Collaborator

RRosio commented Oct 31, 2023

Hi @link89 this looks like a question about ipywidgets. There is already an issue about blocking execution in that repository. Please add your thoughts there, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status:Needs Triage Applied to issues that need triage
Projects
None yet
Development

No branches or pull requests

2 participants