Skip to content

Instantly share code, notes, and snippets.

@robbles
Forked from lepture/gevent-flask.py
Last active December 21, 2015 13:30
Show Gist options
  • Save robbles/6313290 to your computer and use it in GitHub Desktop.
Save robbles/6313290 to your computer and use it in GitHub Desktop.
def runserver(app, port=5000, profile_log=None):
"""Runs a development server."""
from werkzeug.serving import run_with_reloader
from werkzeug.debug import DebuggedApplication
from werkzeug.contrib.profiler import ProfilerMiddleware
app.debug = True
port = int(port)
if profile_log:
f = open(profile_log, 'w')
wsgi = ProfilerMiddleware(app, f)
else:
wsgi = DebuggedApplication(app)
@run_with_reloader
def run_server():
print('start server at: 127.0.0.1:%s' % port)
# import gevent in child process to avoid "gevent is only usable from a single thread" error
from gevent.wsgi import WSGIServer
http_server = WSGIServer(('', port), wsgi)
http_server.serve_forever()
run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment