Skip to content

Encourage creation of aiohttp public objects inside a coroutine #3331

@asvetlov

Description

@asvetlov

I would enforce it. For example, constructing CleintSession in a module global namespace is a bad smell and leads to hard-to-debug errors very often.

The plan is:

  1. Add helpers.get_running_loop() function with the following implementation:
def get_running_loop(loop=None):
    if loop is None:
        loop = asyncio.get_event_loop()
    if not loop.is_running():
        warnings.warn("The object should be created from async function",
                                 DeprecationWarning,
                                 stacklevel=3)
  1. Replace asyncio.get_event_loop() with get_running_loop() in all aiohttp objects.
  2. Replace a deprecation warning with RuntimeError() in aiohttp 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions