Skip to content

Instantly share code, notes, and snippets.

@renaud
Created April 10, 2014 08:35
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save renaud/10356841 to your computer and use it in GitHub Desktop.
Save renaud/10356841 to your computer and use it in GitHub Desktop.
Example of Tornado that autoreloads/watches all files in folder 'static'
'''
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()
@fannyfauzi
Copy link

very helpfull

@jmjpro
Copy link

jmjpro commented Feb 9, 2017

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