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.

Python 3.8.2 breaks nest-asyncio

See original GitHub issue

This trivial demo works with CPython 3.8.1 and breaks with 3.8.2:

import asyncio
import nest_asyncio
nest_asyncio.apply()


async def f():
    print("OK")


async def g():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(f())

if __name__ == "__main__":
    asyncio.run(g())

Works

  • Linux x64, anaconda, nest_asyncio 1.2.2
  • python=3.8.1=h357f687_2 (conda-forge)

Output: OK

Broken

  • Linux x64, anaconda, nest_asyncio 1.2.2
  • python=3.8.2=h9d8adfe_1_cpython (conda-forge)

Output: RuntimeError: This event loop is already running

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
nabobaliscommented, Apr 28, 2020

Just wanted to say I had this issue as well on python 3.8.2 and adding this to my conftest.py worked:

import pytest
import asyncio
import nest_asyncio


@pytest.fixture(scope="session")
def event_loop():
    """
    Don't close event loop at the end of every function decorated by
    @pytest.mark.asyncio
    """
    loop = asyncio.new_event_loop()
    nest_asyncio.apply()
    yield loop
    loop.close()
1reaction
gimperialecommented, Mar 11, 2020

Tested 1.3 vs Python 3.8.2; everything works for me. @gordonwatts pytest-asyncio tampers with the asyncio event loop. I use it too but I was very careful not to mix it with nest-asyncio, uvloop, etc.

Try adding to your conftest.py:

@pytest.fixture(scope="session")
def event_loop():
    """Don't close event loop at the end of every function decorated by
    @pytest.mark.asyncio
    """
    loop = asyncio.new_event_loop()
    yield loop
    loop.close()
Read more comments on GitHub >

github_iconTop Results From Across the Web

nest-asyncio - PyPI
Introduction. By design asyncio does not allow its event loop to be nested. This presents a practical problem: When in an environment where...
Read more >
asyncio: works in Python 3.10 but not in Python 3.8
A glimpse at the asyncio code showed that the Python versions differ a lot. However, the Semaphores can't be just broken in 3.8,...
Read more >
Release notes — Anaconda documentation
Anaconda Navigator has been updated to v2.3.1. This installer uses python-3.9. This is the first release that provides a python-3.10 variant for anaconda ......
Read more >
Python on Biowulf - NIH HPC
There are three distinct ways to run python code or applications on biowulf: ... cache likely were broken during the transition and will...
Read more >
2020-May.txt - Python mailing list
... b/Doc/whatsnew/3.8.rst @@ -2234,3 +2234,8 @@ Notable changes in Python 3.8.2 Fixed a regression with the ``ignore`` callback of :func:`shutil.copytree`.
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