question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jrbourbeaucommented, Jan 17, 2020

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

0reactions
jrbourbeaucommented, Jan 17, 2020

Great, I’ll open a PR adding that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python3.6 AttributeError: module 'asyncio' has no attribute 'run'
When you grab the existing event loop, I'd not close it.. asyncio.run() only closes the loop because it actually creates a new loop...
Read more >
module 'asyncio' has no attribute '_get_running_loop'
Hi All,. I am using channels to implement WebSockets. I am trying to send data through WebSockets from post_save django signal. Below is...
Read more >
AttributeError: module 'asyncio' has no attribute 'get_event_loop
Hi all. I am trying to use Python asyncio module. Adding my code snippet below : import asyncio async def speak_async():
Read more >
deprecationwarning: there is no current event loop event_loop ...
It is better to launch your main task with asyncio.run than loop.run_forever, ... 'Future' object has no attribute 'get_loop' _tests.py:24: AttributeError ...
Read more >
module 'asyncio' has no attribute 'async' - Red Hat Bugzilla
Bug 1899952 - python-brother fails to build with Python 3.10: AttributeError: module 'asyncio' has no attribute 'async'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found