glue-jupyter icon indicating copy to clipboard operation
glue-jupyter copied to clipboard

EXP: Attempt to run ViewListener inside a thread

Open astrofrog opened this issue 1 year ago • 1 comments

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?

astrofrog avatar Oct 29 '24 12:10 astrofrog

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 https://github.com/jupyter-widgets/ipywidgets/issues/1349 https://github.com/jupyter-widgets/ipywidgets/issues/1287

maartenbreddels avatar Oct 29 '24 12:10 maartenbreddels