Skip to content

import GatewayConnector fails with no event loop #605

Open
@vdytyniak-exos

Description

@vdytyniak-exos

I am trying to import Gateway in a separate thread and it fails with:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/exos/loop_error.py", line 3, in <module>
    from dask_gateway import Gateway, GatewayCluster
  File "/usr/local/lib/python3.10/site-packages/dask_gateway/__init__.py", line 5, in <module>
    from .client import (
  File "/usr/local/lib/python3.10/site-packages/dask_gateway/client.py", line 25, in <module>
    from . import comm
  File "/usr/local/lib/python3.10/site-packages/dask_gateway/comm.py", line 29, in <module>
    class GatewayConnector(Connector):
  File "/usr/local/lib/python3.10/site-packages/dask_gateway/comm.py", line 31, in GatewayConnector
    _resolver = netutil.ExecutorResolver(close_executor=False, executor=_executor)
  File "/usr/local/lib/python3.10/site-packages/tornado/util.py", line 288, in __new__
    instance.initialize(*args, **init_kwargs)
  File "/usr/local/lib/python3.10/site-packages/tornado/netutil.py", line 427, in initialize
    self.io_loop = IOLoop.current()
  File "/usr/local/lib/python3.10/site-packages/tornado/ioloop.py", line 263, in current
    loop = asyncio.get_event_loop()
  File "/usr/local/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'AnyIO worker thread'.

Issue related to GatewayConnector initialisation:

class GatewayConnector(Connector):
    _executor = ThreadPoolExecutor(2)
    _resolver = netutil.ExecutorResolver(close_executor=False, executor=_executor)
    ...

ExecutorResolver tries to IOLoop.current() and fails.

Is it possible to release the fix and don't call IOLoop.current() on import?

Versions:
dask-gateway==2022.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions