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

@asvetlov asvetlov commented Feb 14, 2018

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

@samuelcolvin samuelcolvin commented Feb 14, 2018

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

@asvetlov asvetlov commented Feb 14, 2018

@webknjaz
Copy link
Member

@webknjaz webknjaz commented Feb 14, 2018

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

@asvetlov
Copy link
Member Author

@asvetlov asvetlov commented Feb 17, 2018

The change is easy:

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

in very beginning of run_app function.

Any volunteer?

@webknjaz
Copy link
Member

@webknjaz webknjaz commented Feb 17, 2018

it's say try/except instead

@asvetlov
Copy link
Member Author

@asvetlov asvetlov commented Feb 17, 2018

try:
     app = await app
except TypeError:
     pass

looks really strange for me

@webknjaz
Copy link
Member

@webknjaz webknjaz commented Feb 17, 2018

but follows EAFP

@asvetlov
Copy link
Member Author

@asvetlov asvetlov commented Feb 17, 2018

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

@webknjaz webknjaz commented Feb 17, 2018

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

@asvetlov
Copy link
Member Author

@asvetlov asvetlov commented Feb 17, 2018

singledispatch actually - that's the problem

@chuck1
Copy link

@chuck1 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 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

@asvetlov asvetlov commented Mar 13, 2018

Done by #2765

@lock
Copy link

@lock 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.