Skip to content
New issue

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

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

Already on GitHub? # to your account

EXP: Attempt to run ViewListener inside a thread #473

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

astrofrog
Copy link
Member

@astrofrog astrofrog commented Oct 29, 2024

This is an experiment to see what happens when we try and use threads in glue-jupyter. This PR is trying to solve the issue mentioned in #472, specifically that:

app.imshow()
time.sleep(10)

would not show any image until after the sleep, because the callback from the ViewListener is not executed until then. I naively thought that doing something like in this PR would help - setting up and running the ViewListener inside a thread, but this does not help - the _on_view_change method is still only called after the rest of the cell has run.

Full example to try out this PR, avoiding sleep in case it behaves in a special way with respect to threads:

from glue_jupyter import jglue
import numpy as np
import time

app = jglue(settings={'disable_output_widget': True})
app.add_data(image=np.random.random((4096, 4096)))

image = app.imshow()
start = time.time()
while time.time() - start < 5:
    pass

@maartenbreddels - do you understand what might be going on and why this does not work?

@maartenbreddels
Copy link
Collaborator

Hmm. I am starting to wonder if what we want to do is possible at all. The kernel will only process messages after it is done executing. See jupyter-widgets/ipywidgets#1349 jupyter-widgets/ipywidgets#1287

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants