-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor bootstrap.py: Move HTTP server initialization to a separate …
…class.
- Loading branch information
Showing
9 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# coding=utf-8 | ||
"""Module for starting the WSGI Server and the web application itself.""" | ||
from gevent.pywsgi import WSGIServer | ||
|
||
|
||
class ServerRunner: | ||
"""Sets up the HTTP server (WSGI, if not in debug mode) and runs it.""" | ||
|
||
def __init__(self): | ||
"""Once initialized, contains the port where the application will listen.""" | ||
self.started_on_port = None | ||
|
||
def initialize(self, app, app_config): | ||
"""Prepare the server to run and determine the port.""" | ||
debug = app_config["debug"] | ||
port = app_config["http.port"] | ||
if debug: | ||
self.started_on_port = port | ||
app.run(host="0.0.0.0", debug=True, port=port) | ||
else: | ||
for port in range(port, port + 50): | ||
self.http_server = WSGIServer(('0.0.0.0', port), app) | ||
try: | ||
self.http_server.start() | ||
except OSError as e: | ||
# try next port | ||
continue | ||
self.started_on_port = port | ||
break | ||
|
||
def run_server(self): | ||
"""Start the server.""" | ||
self.http_server.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters