Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

AttributeError: module 'asyncio' has no attribute 'get_running_loop' #3381

Closed
haje01 opened this issue Jan 17, 2020 · 5 comments · Fixed by #3383
Closed

AttributeError: module 'asyncio' has no attribute 'get_running_loop' #3381

haje01 opened this issue Jan 17, 2020 · 5 comments · Fixed by #3383

Comments

@haje01
Copy link

haje01 commented Jan 17, 2020

In Jupyter Lab, If I run:

import distributed

causes AttributeError: module 'asyncio' has no attribute 'get_running_loop' error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-432545581521> in <module>()
----> 1 import distributed

~/anaconda3/lib/python3.6/site-packages/distributed/__init__.py in <module>()
      1 from . import config
      2 from dask.config import config
----> 3 from .actor import Actor, ActorFuture
      4 from .core import connect, rpc
      5 from .deploy import LocalCluster, Adaptive, SpecCluster, SSHCluster

~/anaconda3/lib/python3.6/site-packages/distributed/actor.py in <module>()
      5 from queue import Queue
      6 
----> 7 from .client import Future, default_client
      8 from .protocol import to_serialize
      9 from .utils import sync

~/anaconda3/lib/python3.6/site-packages/distributed/client.py in <module>()
     47 from asyncio import iscoroutine
     48 
---> 49 from .batched import BatchedSend
     50 from .utils_comm import (
     51     WrappedKey,

~/anaconda3/lib/python3.6/site-packages/distributed/batched.py in <module>()
      6 from tornado.ioloop import IOLoop
      7 
----> 8 from .core import CommClosedError
      9 from .utils import parse_timedelta
     10 

~/anaconda3/lib/python3.6/site-packages/distributed/core.py in <module>()
     16 from tornado.locks import Event
     17 
---> 18 from .comm import (
     19     connect,
     20     listen,

~/anaconda3/lib/python3.6/site-packages/distributed/comm/__init__.py in <module>()
----> 1 from .addressing import (
      2     parse_address,
      3     unparse_address,
      4     normalize_address,
      5     parse_host_port,

~/anaconda3/lib/python3.6/site-packages/distributed/comm/addressing.py in <module>()
      3 
      4 from . import registry
----> 5 from ..utils import get_ip_interface
      6 
      7 

~/anaconda3/lib/python3.6/site-packages/distributed/utils.py in <module>()
   1205         if is_kernel():
   1206             try:
-> 1207                 asyncio.get_running_loop()
   1208             except RuntimeError:
   1209                 is_kernel_and_no_running_loop = True

AttributeError: module 'asyncio' has no attribute 'get_running_loop'

My Environment:

  • OS : Ubuntu 16.04.6 LTS
  • Python : 3.6.6
  • distributed : 2.9.2
  • tornado: 5.0.2

Strangely, command line python interpreter does not raise the error.
distributed 2.9.1 worked fine.

@TomAugspurger
Copy link
Member

Thanks for the report. Seems that get_running_loop was added in 3.7: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop

That line is only executed in jupyter notebook / lab, which explains why it doesn't happen in the python interpreter (and why our CI didn't catch it, I think).

xref #3336. @potpath do you know of a way to do that check that's compatible with Python 3.6?

@jrbourbeau
Copy link
Member

Thank you @haje01 for reporting this!

Although it's not a great solution, we could use the private asyncio._get_running_loop() method

https://github.com/python/cpython/blob/99eb70a9eb9493602ff6ad8bb92df4318cf05a3e/Lib/asyncio/events.py#L681-L690

as a short term fix.

Another option is to revert #3336

cc @jcrist who has asyncio experience

@jrbourbeau
Copy link
Member

I'll plan to push out a 2.9.3 release of distributed once this issue is resolved

@jcrist
Copy link
Member

jcrist commented Jan 17, 2020

Yeah, I've been using this compat in other projects:

import sys

if sys.version_info[:2] >= (3, 7):
    from asyncio import get_running_loop
else:
    from asyncio import _get_running_loop as get_running_loop

@jrbourbeau
Copy link
Member

Great, I'll open a PR adding that

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

Successfully merging a pull request may close this issue.

4 participants