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.

Async error: event loop already running

See original GitHub issue

Not sure this is an IPython issue because it happens only in a Jupyter Notebook, but the following code gives a RuntimeError: This event loop is already running (IPython 7.0.1, Python 3.7.0, notebook server 5.7.0). No problem with IPython 7.0.1, Python 3.6.3, notebook server 5.3.1.

import asyncio

async def foo():
    await asyncio.sleep(1)
    print('done')

loop = asyncio.get_event_loop()

loop.run_until_complete(foo())

Issue Analytics

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

github_iconTop GitHub Comments

35reactions
davidbrochartcommented, Jun 19, 2020

Having this a the beginning of your notebook should fix this issue:

import nest_asyncio
nest_asyncio.apply()
5reactions
Carreaucommented, Sep 27, 2018

Yes, is is documented in the what’s new and auto-async documentation with pointer to workarounds.

Thanks for testing IPython 7.0 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: This event loop is already running in python
One way is to pass in a synchronous callback to be called once the async operation finishes. That will of course slow down...
Read more >
How to get around “RuntimeError: This event loop is already ...
The solution was to use nest-asyncio. This package patches “asyncio” and allows nested usage “loop. run_until_complete”. I have simply patched ...
Read more >
Supporting asyncio.get_event_loop().run_until_complete() in ...
The above tries to use get_running_loop() first to fetch the currently running event loop, but if there's not one, it uses get_event_loop() ...
Read more >
RuntimeError: This event loop is already running in python
PYTHON : RuntimeError: This event loop is already running in python [ Gift : Animated Search Engine ...
Read more >
Running asyncio — Mastering JupyterLab - NO Complexity
But it can be done. If done wrong the error message: This event loop is already running appears. For any asyncio functionality ...
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