Skip to content

RuntimeError: no running event loop #8555

Closed
@tomplus

Description

Describe the bug

It looks like a breaking change in the latest version.

In version 3.9.5 it works:

import aiohttp
connector = aiohttp.TCPConnector()

(in a more complex example I get a warning (DeprecationWarning: The object should be created within an async function))

but in 3.10 I get an exception:

Traceback (most recent call last):
  File "/tmp/a1.py", line 5, in <module>
    connector = aiohttp.TCPConnector()
  File "/home/tomek/work/github/kubernetes-client/kubernetes_asyncio-new/VENV/lib/python3.10/site-packages/aiohttp/connector.py", line 784, in __init__
    super().__init__(
  File "/home/tomek/work/github/kubernetes-client/kubernetes_asyncio-new/VENV/lib/python3.10/site-packages/aiohttp/connector.py", line 234, in __init__
    loop = loop or asyncio.get_running_loop()
RuntimeError: no running event loop

To Reproduce

code

import aiohttp
connector = aiohttp.TCPConnector()

Expected behavior

If the change is intentional it would be very useful to describe that in a changelog.
If not I expect the same behavior like in the previous version.

Logs/tracebacks

Traceback (most recent call last):
  File "/tmp/a1.py", line 5, in <module>
    connector = aiohttp.TCPConnector()
  File "/home/tomek/work/github/kubernetes-client/kubernetes_asyncio-new/VENV/lib/python3.10/site-packages/aiohttp/connector.py", line 784, in __init__
    super().__init__(
  File "/home/tomek/work/github/kubernetes-client/kubernetes_asyncio-new/VENV/lib/python3.10/site-packages/aiohttp/connector.py", line 234, in __init__
    loop = loop or asyncio.get_running_loop()
RuntimeError: no running event loop


### Python Version

```console
$ python --version
3.10

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.10.0

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.4

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.8.2

OS

Linux

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions