-
-
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
WIP Server class to start applications #2465
Conversation
641b49f
to
05148c3
Compare
@asvetlov is it more or less the idea you had in mind? |
@@ -27,7 +27,7 @@ | |||
from .web_protocol import * # noqa | |||
from .web_request import * # noqa | |||
from .web_response import * # noqa | |||
from .web_server import Server | |||
from .web_server import Server as WebServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename web_server.Server into web_server.WebServer to avoid collisions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break retro compatibility but we can maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I just saw this in a test traceback:
> srv = web.Server(handler)
E TypeError: __init__() takes 1 positional argument but 2 were given
Which means the name Server is exported in aiohttp.web
so I need to find another name than Server
to avoid breaking compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, better to avoid this name collision somehow.
aiohttp/web.py
Outdated
self.backlog = backlog | ||
self.access_log_format = access_log_format | ||
self.access_log = access_log | ||
self.base_url = URL('{}://localhost'.format(scheme)).with_port(port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL.build
was pretty nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry I missed this one 😀 I based my branch on an old version by mistake then I rebased too late when I realized my mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! Would be nice to see few examples about it usage.
return asyncio.gather(*server_creations, loop=self.loop) | ||
|
||
@asyncio.coroutine | ||
def start(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could I start specific app in runtime after starting all the apps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean. This is not meant to start selectively the applications. This is meant to group all the target applications and run them together on one connection. I mostly inspired on hapi's Glue for the concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if Server object manages multiple applications, then why not you can't use it to register/start/stop arbitrary application is runtime? Quite oblivious task for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't make it with the idea of changing the applications during runtime at all but it sounds like an interesting use case.
return self.uris | ||
|
||
@asyncio.coroutine | ||
def stop(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could I stop specific app in runtime?
self._apps = [] | ||
self._servers = None | ||
|
||
def register(self, app, *, prefix="/"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could I unregister specific app in runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't at the moment. It's not meant to be mutable. I can try to implement it but this is not my priority. The code to create a server and register apps is pretty small and I suppose it's best to just re-instantiate a new one if you need to change something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-instantiate a new server means to stop all the applications and cause a downtime. Not a good behaviour for adding a new app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same comment: it wasn't meant to avoid downtime, it was meant to allow running the apps without having to make aiohttp the center of the process)
I will give thorough examples and documentation if this is what we want for aiohttp to handle multiple applications (and running the applications without being the main process). Right now all I can say is that you could potentially do this: Imagine you want to run side by side a grpc server and an application. Now you can by creating dynamically a It also helps to gather I suppose there are a lot of use cases for this but to be honest I have never encountered one yet professionally since I mostly did microservices. Maybe @alexmnazarenko could give his input on this feature. It's just a sample at this point, we can add |
Looks as good concept.
Running P.S. |
It tried to read in your mind 😀
👍
That sounds like a great idea!
Wait I'm lost. So you would rename Application to Site and this new Server to Application? But then it's TCPApplication, UnixApplication and SocketApplication isn't it? Also you can do a major release if you rename everything like that. |
No. |
Superseded by #2530 |
You're welcome :) I'm glad it helped! |
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. |
What do these changes do?
Attempt to answer to the issue raised on #2121 and #2375 by creating a
Server
class capable of registering multiple applications and providing astart()
and astop()
asynchronous methods to allow the developers to open and close the server sockets to the application.Are there changes in behavior for the user?
Added a Server class.
web.run_app
is preserved.Related issue number
#2121 #2375
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.