Commit 6f6a9f4a authored by Robin Schoonover's avatar Robin Schoonover
Browse files

Add --call flag to call "wsgiapp" to actually get wsgiapp.

parent b4e15c53
......@@ -7,11 +7,15 @@ def main():
parser = argparse.ArgumentParser('Reloading WSGI Development Server')
parser.add_argument('--host', default='localhost')
parser.add_argument('--port', default=8080, type=int)
parser.add_argument('--call', action='store_true', dest='call_app')
parser.add_argument('wsgiapp')
args = parser.parse_args()
server = Server(args.wsgiapp, host=args.host, port=args.port)
server = Server(args.wsgiapp,
host=args.host,
port=args.port,
call_app=args.call_app)
server.run_forever()
if __name__=='__main__':
......
......@@ -18,10 +18,11 @@ class FailedApp(object):
return [b"Failed: ", self.msg.encode('utf-8'), b"\n"]
class Server(object):
def __init__(self, app, host="0.0.0.0", port=80):
def __init__(self, app, host="0.0.0.0", port=80, call_app=False):
self.app = app
self.host = host
self.port = port
self.call_app = call_app
self.last_start = 0
......@@ -47,6 +48,7 @@ class Server(object):
self.last_start = now
proc = multiprocessing.Process(target=ServerChild.launch, kwargs={
'call_app' : self.call_app,
'app' : self.app,
'host' : self.host,
'port' : self.port
......@@ -55,8 +57,9 @@ class Server(object):
return proc
class ServerChild(object):
def __init__(self, app, host, port):
def __init__(self, app, host, port, call_app):
self.app = app
self.call_app = call_app
self.host = host
self.port = port
......@@ -88,11 +91,20 @@ class ServerChild(object):
module = sys.modules[module_name]
try:
return getattr(module, func_name)
app = getattr(module, func_name)
except AttributeError as exc:
log.exception("Failed to load attr %s from module", func_name)
return FailedApp("Import failed (%s)"%(exc, ))
if self.call_app:
try:
app = app()
except Exception as exc:
log.exception("Error while calling app")
return FailedApp("Call failed (%s)"%(exc,))
return app
def server_init(self):
from waitress import create_server
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment