InsightSoftwareConsortium / itkwidgets

An elegant Python interface for visualization on the web platform to interactively generate insights into multidimensional images, point sets, and geometry.
https://itkwidgets.readthedocs.io/
Apache License 2.0
574 stars 83 forks source link

CellWatcher use of ZMQStream with JupyterLite #730

Open thewtex opened 6 months ago

thewtex commented 6 months ago

@bnmajor looking to update our docs JupyterLite itkwidgets version, and I am getting the following traceback:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 1
----> 1 from itkwidgets import view
      2 import imageio.v2 as imageio

File /lib/python3.10/site-packages/itkwidgets/__init__.py:12
      9     from .imjoy import register_itkwasm_imjoy_codecs
     10     register_itkwasm_imjoy_codecs()
---> 12 from .viewer import Viewer, view, compare_images
     13 from .standalone_server import standalone_viewer
     15 __all__ = [
     16   "Viewer",
     17   "view",
     18   "compare_images",
     19   "standalone_viewer",
     20 ]

File /lib/python3.10/site-packages/itkwidgets/viewer.py:25
     17 from ._type_aliases import Gaussians, Style, Image, PointSet, CroppingPlanes
     18 from ._initialization_params import (
     19     init_params_dict,
     20     build_config,
   (...)
     23     defer_for_data_render,
     24 )
---> 25 from .cell_watcher import CellWatcher
     26 from .imjoy import register_itkwasm_imjoy_codecs
     27 from .integrations import _detect_render_type, _get_viewer_image, _get_viewer_point_set

File /lib/python3.10/site-packages/itkwidgets/cell_watcher.py:9
      7 from queue import Queue
      8 from imjoy_rpc.utils import FuturePromise
----> 9 from zmq.eventloop.zmqstream import ZMQStream
     11 background_tasks = set()
     14 class Viewers(object):

ModuleNotFoundError: No module named 'zmq'
thewtex commented 6 months ago

@bnmajor Viewers run with #731 but getters still failing with

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[6], line 1
----> 1 viewer.get_rotate()

File /lib/python3.10/site-packages/itkwidgets/viewer.py:324, in Viewer.fetch_value.<locals>._fetch_value(self, *args, **kwargs)
    322 if isawaitable(result):
    323     future = asyncio.ensure_future(result)
--> 324     self.call_getter(future)
    325     return future
    326 return result

File /lib/python3.10/site-packages/itkwidgets/viewer.py:288, in Viewer.call_getter(self, future)
    286 global _cell_watcher
    287 name = uuid.uuid4()
--> 288 _cell_watcher.results[name] = future
    289 future.add_done_callback(functools.partial(_cell_watcher._callback, name))

AttributeError: 'NoneType' object has no attribute 'results'
thewtex commented 6 months ago

As discussed with @bnmajor, we will need to teach CellWatcher to operate on the Jupyter message stream in JupyterLite as we do with JupyterNotebook / JupyterLab with the ZMQStream.