ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
120 stars 77 forks source link

ImageViewJpw gives DeprecationWarning: There is no current event loop #1033

Closed pllim closed 1 year ago

pllim commented 1 year ago

Saw this downstream in astrowidgets pre-release testing. I am going to ignore this warning downstream but thought maybe it is something Ginga should handle?

xref https://github.com/astropy/astrowidgets/pull/156

Example log: https://github.com/astropy/astrowidgets/actions/runs/3658672508/jobs/6183750830

>       image = ImageWidget()

../../astrowidgets/tests/test_api.py:17: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../astrowidgets/core.py:104: in __init__
    self._viewer.set_widget(self._jup_img)
.../ginga/web/jupyterw/ImageViewJpw.py: in set_widget
    super(ImageViewEvent, self).set_widget(jp_imgw)
.../ginga/web/jupyterw/ImageViewJpw.py:96: in set_widget
    self._defer_task = JpHelp.Timer()
.../ginga/web/jupyterw/JpHelp.py:115: in __init__
    self._timer = self.timer_factory.add_timer(self._redirect_cb)
.../ginga/web/jupyterw/JpHelp.py:75: in add_timer
    self.wind()
.../ginga/web/jupyterw/JpHelp.py:43: in wind
    self._timeout = IOLoop.current().add_timeout(delta, self.timer_tick)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

instance = True

    @staticmethod
    def current(instance: bool = True) -> Optional["IOLoop"]:  # noqa: F811
        """Returns the current thread's `IOLoop`.

        If an `IOLoop` is currently running or has been marked as
        current by `make_current`, returns that instance.  If there is
        no current `IOLoop` and ``instance`` is true, creates one.

        .. versionchanged:: 4.1
           Added ``instance`` argument to control the fallback to
           `IOLoop.instance()`.
        .. versionchanged:: 5.0
           On Python 3, control of the current `IOLoop` is delegated
           to `asyncio`, with this and other methods as pass-through accessors.
           The ``instance`` argument now controls whether an `IOLoop`
           is created automatically when there is none, instead of
           whether we fall back to `IOLoop.instance()` (which is now
           an alias for this method). ``instance=False`` is deprecated,
           since even if we do not create an `IOLoop`, this method
           may initialize the asyncio loop.

        .. deprecated:: 6.2
           It is deprecated to call ``IOLoop.current()`` when no `asyncio`
           event loop is running.
        """
        try:
>           loop = asyncio.get_event_loop()
E           DeprecationWarning: There is no current event loop

.../tornado/ioloop.py:265: DeprecationWarning