Aiohttp: Accept a coroutine in web.run_app

Created on 14 Feb 2018  路  14Comments  路  Source: aio-libs/aiohttp

The proposal allows to execute async IO before creating an application

enhancement good first issue outdated server

All 14 comments

How does this differ from on_startup?

Surely too many options will for the default way to run a server will confuse new users?

Sounds reasonable, I'd like to see the implementation draft for it.

The change is easy:

if asyncio.iscoroutine(app):
    app = await app

in very beginning of run_app function.

Any volunteer?

it's say try/except instead

try:
     app = await app
except TypeError:
     pass

looks really strange for me

but follows EAFP

It is not forgiveness/permission problem but overloading accepted types.
In static typed language it should be two functions with the same name but different parameter types.

yeah, and there's functools.dispatch() for that it Python

singledispatch actually - that's the problem

would this feature allow you to run the app asynchronously? in other words an async equivalent of the aiohttp.web.run_app function?

@chuck1 no. run_app instantiates and closes an event loop instance.

But you can run an app from in a coroutine by three lines of code, 2 for initializing and 1 for shutdown: https://docs.aiohttp.org/en/stable/web_advanced.html#application-runners

Done by #2765

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoseKilo picture JoseKilo  路  3Comments

Codeberg-AsGithubAlternative-buhtz picture Codeberg-AsGithubAlternative-buhtz  路  3Comments

Smosker picture Smosker  路  3Comments

deckar01 picture deckar01  路  4Comments

JulienPalard picture JulienPalard  路  3Comments