Created
April 10, 2014 08:35
-
-
Save renaud/10356841 to your computer and use it in GitHub Desktop.
Example of Tornado that autoreloads/watches all files in folder 'static'
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
''' | |
Example of Tornado that autoreloads/watches all files in folder 'static' | |
''' | |
import tornado.ioloop | |
import tornado.web | |
import tornado.autoreload | |
import os | |
''' serves index.html''' | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.render('static/index.html') | |
application = tornado.web.Application([ | |
(r'/', MainHandler), | |
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': 'static/'}) | |
],gzip=True) | |
if __name__ == "__main__": | |
application.listen(8888) | |
#TODO remove in prod | |
tornado.autoreload.start() | |
for dir, _, files in os.walk('static'): | |
[tornado.autoreload.watch(dir + '/' + f) for f in files if not f.startswith('.')] | |
tornado.ioloop.IOLoop.instance().start() |
Thanks much this worked for me! If tornado is running in a docker container see http://stackoverflow.com/a/23455537/567525 for an additional step needed to map a directory from the host to the container.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very helpfull