Skip to content

Python 3.10 - DeprecationWarning on example server sample #6752

Description

@2-5

Describe the bug

In Python 3.10 you'll get a DeprecationWarning If you run the server example

To Reproduce

Run example code from documentation main page: https://docs.aiohttp.org/en/stable/index.html#server-example

from aiohttp import web

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/{name}', handle)])

if __name__ == '__main__':
    web.run_app(app)  # <------- calls asyncio.get_event_loop() with no running loop

Expected behavior

No DeprecationWarning, example modified to show the proper way to run it under Python 3.10

Logs/tracebacks

/venv3/lib/site-packages/aiohttp/web.py:479: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
======== Running on http://0.0.0.0:8080 ========

Python Version

Python 3.10.4

aiohttp Version

aiohttp 3.7.4.post0

multidict Version

-

yarl Version

-

OS

Windows 10

Related component

Server

Additional context

No response

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions