Revisions
-
jacobk revised this gist
Dec 1, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def get(self): def _check(self): if self._are_where_there_yet(): self.scheduler.stop() self.write("Hello, world") self.finish() def _are_where_there_yet(self): -
jacobk revised this gist
Dec 1, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ def get(self): def _check(self): if self._are_where_there_yet(): self.scheduler.stop() self.write("Hello, World!") self.finish() def _are_where_there_yet(self): -
jacobk created this gist
Dec 1, 2009 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ import logging import random import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options define("port", default=8888, help="run on the given port", type=int) class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): import tornado.ioloop self.scheduler = tornado.ioloop.PeriodicCallback(self._check, 1e3) self.scheduler.start() def _check(self): if self._are_where_there_yet(): self.scheduler.stop() self.write("CHANGE DETECTED!") self.finish() def _are_where_there_yet(self): n = random.randint(1,10) logging.info("current value: %s", n) return n == 5 def main(): tornado.options.parse_command_line() application = tornado.web.Application([ (r"/", MainHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()