def run(self): # setups self.setup_application() self.setup_api() # start periodic update thread pa = api.PeriodicUpdater() pa.start() # start API server if False: # default server: logging.info("API Server: Pure Flask") self.app.run(debug=False, use_reloader=False, port=model.CONFIG["api"]["port"]) elif False: logging.info("API Server: Gevent") from gevent.wsgi import WSGIServer http_server = WSGIServer(('', model.CONFIG["api"]["port"]), self.app) http_server.serve_forever() else: logging.info("API Server: Tornado") from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(self.app)) http_server.listen(model.CONFIG["api"]["port"]) IOLoop.instance().start()
def serve_app(environment): """ Serve your application. If a server argument is not passed, then your application will be run through Flask's development server. """ 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) http_server.serve_forever() elif environment.tornado: from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(app)) http_server.listen(port) IOLoop.instance().start() else: app.run(debug=True, port=port)
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) http_server.serve_forever() elif environment.tornado: from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(app)) http_server.listen(port) IOLoop.instance().start() else: app.run(debug=True, port=port)
t = Thread(target=put2Redis, name='Application.Register2Redis') t.start() try: logger.info('%s has been launched, %s:%d' %(ProcessName, Host, Port)) if ProductType == 'gevent': from gevent.wsgi import WSGIServer http_server = WSGIServer((Host, Port), app) http_server.serve_forever() elif ProductType == 'tornado': from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(app)) http_server.listen(Port) IOLoop.instance().start() elif ProductType == "uwsgi": try: import os from sh import uwsgi from multiprocessing import cpu_count BASE_DIR= os.path.dirname(os.path.abspath(__file__)) logfile = os.path.join(BASE_DIR, 'logs', 'uwsgi.log') if os.path.exists('uwsgi.ini'): uwsgi("--http", "%s:%d"%(Host,Port), "--procname-master", ProcessName, "--procname", ProcessName + ".worker", "--chdir", BASE_DIR, "-w", "api:app", "-d", logfile, "-M", "-p", cpu_count(), "--ini", "uwsgi.ini") else: uwsgi("--http", "%s:%d"%(Host,Port), "--procname-master", ProcessName, "--procname", ProcessName + ".worker", "--chdir", BASE_DIR, "-w", "api:app", "-d", logfile, "-M", "-p", cpu_count()) except ImportError: errmsg=r"Start Fail, maybe you did not install the `sh` module."
elif appname == 'pyramid': from servers.pyr import app if __name__ == "__main__": if server == 'gevent': from gevent.wsgi import WSGIServer http_server = WSGIServer((HOST, PORT), app, log=None) http_server.serve_forever() elif server == 'tornado': from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(app)) http_server.listen(PORT) IOLoop.instance().start() elif server == 'eventlet': from eventlet import wsgi import eventlet wsgi.server(eventlet.listen(('127.0.0.1', PORT), backlog=500), app, log=file('/dev/null', 'w')) elif server == 'cherrypy': from cherrypy import wsgiserver server = wsgiserver.CherryPyWSGIServer( (HOST, PORT), app, server_name='www.cherrypy.example') server.start()
redisdb = redis.ConnectionPool(host='localhost') @app.route("/") def hello(): db = redis.Redis(connection_pool=redisdb) x = db.incr('counter') p = db.get('page') return "Hello World! %s\n%s" % (x, p) if len(sys.argv) < 2: server = 'tornado' else: server = sys.argv[1] if __name__ == "__main__": if server == 'gevent': from gevent.wsgi import WSGIServer http_server = WSGIServer(('', 8000), app, log=None) http_server.serve_forever() elif server == 'tornado': http_server = HTTPServer(WSGIContainer(app)) http_server.listen(8000) IOLoop.instance().start() else: raise Exception('wat')
def main(): """ Launch the flask application and any user defined tasks. Put stuff here That should not happen when running behind a web server. """ args = commandline() # Information about how and where to run hostname = socket.getfqdn() if args.port: # If this is in use, just let everything fail. # If you've specified a port, then you should know what you are doing. desired_port = args.port else: # Pick a random port and hope that is doesn't get taken # between closing it and starting the app sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('localhost', 0)) desired_port = sock.getsockname()[1] sock.close() url = "http://{}:{}/faps".format(hostname, desired_port) print(">> Starting faps web interface.") print(">> The UI is available at the URL: {}".format(url)) print(">> The URL is accessible from any computer on the same network.") print(">> Use the browser on the machine with your cif files.") if args.no_browser: print(">> Web browser will not be launched. Go to the URL manually.") else: print(">> Attempting to start a web browser...") # Launch first and hope that the server is up by the time the # request is finished webbrowser.open(url) print(">> To exit press Ctrl-C") # App runs here... # Debugging mode uses the internal server, otherwise make use of # gevent to run things if args.debug: app.run(debug=True, host=hostname, port=desired_port) else: try: from gevent.wsgi import WSGIServer http_server = WSGIServer(listener=('', desired_port), application=app, log=None) http_server.serve_forever() except ImportError: from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from tornado.options import options, parse_command_line parse_command_line([None, '--logging=error']) http_server = HTTPServer(WSGIContainer(app)) http_server.listen(desired_port) IOLoop.instance().start()
print 'update bloglist set flag = 1 where id =%d' % (list[0][0]) return json.dumps({'error': todo_id}) import sys if len(sys.argv) > 1: mode = sys.argv[1] else: mode = 'debug' if mode == 'debug': app.run(port=5000, debug=True, host='0.0.0.0') elif mode == 'gevnet': from gevent.wsgi import WSGIServer http_server = WSGIServer(('', 5000), app) http_server.serve_forever() elif mode == 'tornado': from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop http_server = HTTPServer(WSGIContainer(app)) http_server.listen(5000) IOLoop.instance().start() else: app.run(port=5000, debug=True) if __name__ == "__main__": #app.run(port=5000,debug=True) print 12