Created
May 31, 2015 20:58
-
-
Save darvid/8578fab23b8ab9e35903 to your computer and use it in GitHub Desktop.
cross-platform gevent-based WSGI server command for Flask-Script
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
@manager.command | |
def runserver(host="127.0.0.1", port=8000): | |
"""Run a gevent-based WSGI server.""" | |
port = int(port) | |
wrapped_app = app | |
if app.config.get("DEBUG", True): | |
wrapped_app = werkzeug.debug.DebuggedApplication(app) | |
server = WSGIServer(listener=(host, port), application=wrapped_app, | |
handler_class=WebSocketHandler) | |
def serve(): | |
print(" * Running on http://%s:%d/" % (host, port)) | |
server.serve_forever() | |
if app.debug: | |
# the watchdog reloader (with watchdog==0.8.3) appears to hang on | |
# Windows 8.1, so we're using stat instead | |
werkzeug.serving.run_with_reloader( | |
serve, reloader_type="stat" if sys.platform == "win32" else "auto") | |
else: | |
serve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment