Skip to content

Python 3.10 - DeprecationWarning on example "Run a Basic Low-Level Server" #7314

Description

@schuberttobias

Describe the bug

In Python 3.10 you'll get a DeprecationWarning If you run the example Run a Basic Low-Level Server.

To Reproduce

Run example code from documentation:

https://docs.aiohttp.org/en/stable/web_lowlevel.html#run-a-basic-low-level-server

import asyncio
from aiohttp import web


async def handler(request):
    return web.Response(text="OK")


async def main():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', 8080)
    await site.start()

    print("======= Serving on http://127.0.0.1:8080/ ======")

    # pause here for very long time by serving HTTP requests and
    # waiting for keyboard interruption
    await asyncio.sleep(100*3600)


loop = asyncio.get_event_loop()

try:
    loop.run_until_complete(main())
except KeyboardInterrupt:
    pass
loop.close()

Expected behavior

No DeprecationWarnings.

Logs/tracebacks

(aiohttp-test) root@e6dabeed3c80:~/aiohttp-test# python3 test.py
/root/aiohttp-test/test.py:23: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
======= Serving on http://127.0.0.1:8080/ ======

Python Version

3.10.6

aiohttp Version

3.8.4

multidict Version

Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /root/.local/share/virtualenvs/aiohttp-test-WmGPGqKN/lib/python3.10/site-packages
Requires:
Required-by: aiohttp, yarl

yarl Version

Name: yarl
Version: 1.9.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Location: /root/.local/share/virtualenvs/aiohttp-test-WmGPGqKN/lib/python3.10/site-packages
Requires: idna, multidict
Required-by: aiohttp

OS

Ubuntu 22.04.2 LTS (GNU/Linux 4.14.314-237.533.amzn2.x86_64 x86_64)

Related component

Server

Additional context

Related to #6752 and possibly to #6757 #5572

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    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