Find file
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (51 sloc) 1.92 KB
#!/usr/bin/env python
Bootstrap and serve your application. If you're in a development environment,
envoke the script with:
$ python
You can also specify the port you want to use:
$ python 5555
You can easily test the production `tornado` server, too:
$ python --tornado
Alternatively, your application can be run with the `gevent` Python library:
$ python --gevent
import argparse
from app import create_app
def parse_arguments():
"""Parse any additional arguments that may be passed to ``."""
parser = argparse.ArgumentParser()
parser.add_argument('port', nargs='?', default=5000, type=int,
help="An integer for the port you want to use.")
parser.add_argument('--gevent', action='store_true',
help="Run gevent's production server.")
parser.add_argument('--tornado', action='store_true',
help="Run gevent's production server.")
args = parser.parse_args()
return args
def serve_app(environment):
Serve your application. If `dev_environment` is true, then the
application will be served using gevent's WSGIServer.
app = create_app()
# Use the $PORT variable on heroku's environment.
port = environment.port
if environment.gevent:
from gevent.wsgi import WSGIServer
http_server = WSGIServer(('', port), app)
elif environment.tornado:
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
http_server = HTTPServer(WSGIContainer(app))
else:, port=port)
def main():
dev_environment = parse_arguments()
if __name__ == '__main__':