Search code examples
pythonwsgigevent

Hot reload gevent WSGIServer


I've got a Flask app nicely running in a gevent.WSGIServer. For that smooth development experience I would like to enable hot-reload, e.g. if a python loaded python file changes on disk, I would like the server to reload. As I use SSE events that necessarily blocks requests, so I cannot run the otherwise very nice Flask built-in debug server. In production I do not want hot-reload.

I found the @run_with_reloader decorator, but 1) in a code comment the authors advice against using this function and 2) When any function in my main py-file has this decorator hot-reload is always enabled, regardless of that function being called or not.

How can I hot-reload a gevent.WSGIServer during development?


Solution

  • I had the same use case. I found this, and it's working, though it's using twisted: https://gist.github.com/ianschenck/977379a91154fe264897 . A similar approach could work for gevent too.