-
-
Save arnaudsj/253088 to your computer and use it in GitHub Desktop.
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
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("Hello, world") | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment