Skip to content

Instantly share code, notes, and snippets.

@lepture
Last active January 30, 2020 15:29
Show Gist options
  • Save lepture/4040127 to your computer and use it in GitHub Desktop.
Save lepture/4040127 to your computer and use it in GitHub Desktop.
gevent with werkzeug reload and debug
def runserver(port=5000, profile_log=None):
"""Runs a development server."""
from gevent.wsgi import WSGIServer
from werkzeug.serving import run_with_reloader
from werkzeug.debug import DebuggedApplication
from werkzeug.contrib.profiler import ProfilerMiddleware
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)
http_server = WSGIServer(('', port), wsgi)
http_server.serve_forever()
run_server()
@reorx
Copy link

reorx commented Aug 17, 2015

run_with_reloader 不是一个 decorator 啊,这样得到的 run_server 应该是个 None,不能调用的吧。

而且 gevent 1.1 里面这个办法已经不管用了,需要重新写一个用 greenlet 运行 reloader 的 run_with_reloader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment