-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support application coroutine factory in web.run_app and gunicorn worker. #2033
Comments
to me this looks like "coroutines" just for sake of "coroutines", extra complexity without clear reasoning. code |
The problem is initialization order. I understand your position. Maybe we could invite another approach? |
I am not sure how uninitialized application can receive request before make_handler returns? Also who cares about make_handler in general, we have signal. |
No, I'm talking about another scenario:
On stage 3) we have only partially initialized application |
Well, this is definitely bug in flow. There should be no configuration happen beyond make_handler call |
That's why I swapped around |
why run_app() calls startup? breaking encapsulation is really bad. this also means that workers are actually broken. |
It did it starting from very initial version. |
worker does not call startup.
|
Actually it does: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/worker.py#L44-L45
Because it was the only way to setup application's loop before And it is the partial reason for raising this issue. |
worker is still broken, loop is not set when startup get called. just move |
Aah, I see.
|
it doesn't matter, we use we need one method that would finalize app configuration and prepare handler. everything before call to this method should be sync, everything after should be async. |
Not so easy :( It could be done by brand new method though which asserts that current loop is None or not running. |
how is this possible? only worker can call it or run_app method. if someone wants to shoot itself you can't protect them |
2.0 release is several months old, no body complained about |
I've definitely had problems with missing loop in startup, can't remember
how I worked around.
…On 29 Jun 2017 6:32 pm, "Nikolay Kim" ***@***.***> wrote:
2.0 release is several months old, no body complained about startup
method, so high likely nobody needs loop in startup and probably there is
no application init problem
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2033 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD2jGS-JoadxFNdFxti0coNkJLKF1BAxks5sI9-ZgaJpZM4OH02G>
.
|
I personally seen very many code that uses Nobody complained because worker setups default event loop here: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/worker.py#L34-L41 The only broken thing is at this stage |
We din't explicitly forbid it but described Also we do call |
want to complicate configuration, fine. then i am not sure what we are discussing now. |
Home Assistant calls |
I want to find a fix without breaking changes. Let me take a pause until tomorrow. I need think over alternatives. |
ok, they set custom attributes on loop. do you think we should encourage that too? |
I am bored with this issue. want to use coroutines everywhere fine. what introduce new api for each use case fine. just stop talking about clean design. |
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. |
Summary
It should be something like:
web.run_app(make_app)
forrun_app
andgunicorn script:make_app
for Gunicorn.Motivation
We encourage stop passing a loop instance to application.
But the app still needs a loop for it's functionality.
For this we have
app._init_loop(loop)
method which is called imperceptible byrun_app()
and Gunicorn worker. It at least very tricky. Other libraries likeaiohttp-devtool
should also call_init_loop
internally and so on.But creation application object inside a coroutine removes the need for extra loop initializer because the loop is already here implicitly.
To do it we need an asynchronous callback to create an application.
Implementation details
Both parameter for
web.run_app()
and Gunicorn entry point should be eitherweb.Application
entry or a async function which accepts no parameters.In the last case aiohttp calls this function, gets coroutine back and runs the coroutine. Result is and
web.Application
instance.Future improvements
Later we could support async context manager as factory:
While cleanup task could be solved by adding
app.on_cleanup
signal handler maybe somebody prefer more explicit approach.The text was updated successfully, but these errors were encountered: