Created
April 19, 2011 14:47
-
-
Save mopemope/928161 to your computer and use it in GitHub Desktop.
auto reloader for meinheld
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
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