Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a coroutine in web.run_app #2739

Closed
asvetlov opened this issue Feb 14, 2018 · 14 comments
Closed

Accept a coroutine in web.run_app #2739

asvetlov opened this issue Feb 14, 2018 · 14 comments

Comments

@asvetlov
Copy link
Member

The proposal allows to execute async IO before creating an application

@asvetlov asvetlov added this to the 3.1 milestone Feb 14, 2018
@samuelcolvin
Copy link
Member

How does this differ from on_startup?

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

@asvetlov
Copy link
Member Author

It follows new asyncio API: https://docs.python.org/3.7/library/asyncio-task.html#asyncio.asyncio.run

@webknjaz
Copy link
Member

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

@asvetlov asvetlov added the good first issue Good for newcomers label Feb 17, 2018
@asvetlov
Copy link
Member Author

The change is easy:

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

in very beginning of run_app function.

Any volunteer?

@webknjaz
Copy link
Member

it's say try/except instead

@asvetlov
Copy link
Member Author

try:
     app = await app
except TypeError:
     pass

looks really strange for me

@webknjaz
Copy link
Member

but follows EAFP

@asvetlov
Copy link
Member Author

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.

@webknjaz
Copy link
Member

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

@asvetlov
Copy link
Member Author

singledispatch actually - that's the problem

@chuck1
Copy link

chuck1 commented Feb 19, 2018

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

@asvetlov
Copy link
Member Author

asvetlov commented Feb 20, 2018

@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

@asvetlov
Copy link
Member Author

Done by #2765

@lock
Copy link

lock bot commented Oct 28, 2019

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].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants