Skip to content

Instantly share code, notes, and snippets.

@mopemope
Created April 19, 2011 14:47
Show Gist options
  • Save mopemope/928161 to your computer and use it in GitHub Desktop.
Save mopemope/928161 to your computer and use it in GitHub Desktop.
auto reloader for meinheld
from plugpy import *
from plugpy.ext.filewatcher import FileWatchPlugin
from plugpy.ext.autoreloader import AutoReloadPlugin
from meinheld import server
def hello_world(environ, start_response):
status = '200 OK'
res = "Hello world!"
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
#print environ
return [res]
class FileObserver(FileWatchPlugin):
def on_modified(self, created, modified, deleted):
server.stop()
dispatch("reload", target=AutoReloadPlugin)
class AutoReloader(AutoReloadPlugin):
def main_loop(self):
server.listen(("0.0.0.0", 8000))
server.run(hello_world)
def reloader_loop(self):
dispatch("start", target=FileWatchPlugin)
if __name__ == "__main__":
config = dict()
load_plugins(config, debug=False, plugin_class=[FileWatchPlugin, AutoReloadPlugin])
dispatch("start", target=AutoReloadPlugin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment