GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
I am using web.py as an embedded webserver in my app. Because there is no way to set the port served programatically I have to do this
import sys; sys.argv = '8080' #Yuck
self.app = web.application(xxxx)
Otherwise webpy assumes the first command line argument it its port (which it is not as my app has many other command line args)
How about making it take from web.config if specified? Something like this:
web.config.default_port = 8090
I guess that would be sufficient, however I would prefer it be per application (config is global, right?).
Although not needed in my case, someone else might wish to run multiple servers on different ports.
Actually I just saw that config seems to hold other global state (smtp config for example), so there is precident.
web.config.default_port makes sense in that case.
we might want to support specifying the interface too. 127.0.0.1 to bind only on localhost.
Should we call it default_bind_address?
web.ctx.default_bind_address = '127.0.0.1:9000'
or just port:
web.ctx.default_bind_address = 9000
How about just calling it interface?
web.ctx.default_interface = 127.0.0.1:9000
And, in the port only case
web.ctx.default_interface = :9000
(i.e. starts with ':')
This can be solved by calling runsimple like this.
if __name__ == "__main__":
web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", 8888))
For the port only case in web.ctx.default_interface
web.ctx.default_interface = ::1
Do I now listen on port 1 with the default interface or on IPv6 loopback and the default port? Of course this:
web.ctx.default_interface = '[::1]'
would make it clear for IPv6.
I'd like a a default_address (as interfaces can have multiple addresses) and a default_port. Keeping with the explicit is better than implicit (pep-0020, second line in the zen of python) - yes I'm being a smartass here. Sorry :)