Created
January 21, 2017 14:13
-
-
Save BibMartin/eb08cf972c33d5d2552274eaf2e3887f to your computer and use it in GitHub Desktop.
A tornado web service that self-calls itself periodically
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 characters
| import tornado.ioloop | |
| import tornado.web | |
| import pandas as pd | |
| import requests | |
| import os | |
| class MainHandler(tornado.web.RequestHandler): | |
| def get(self): | |
| print('handler', pd.Timestamp.utcnow()) | |
| self.write(str(self.request.headers.get('Authorization'))) | |
| def callback(): | |
| print('callback', pd.Timestamp.utcnow()) | |
| r = requests.get('http://localhost:9999/') | |
| assert r.ok | |
| if __name__ == "__main__": | |
| if os.fork(): | |
| app = tornado.web.Application([ | |
| (r"/", MainHandler), | |
| ]) | |
| app.listen(9999) | |
| tornado.ioloop.IOLoop.current().start() | |
| else: | |
| tornado.ioloop.PeriodicCallback(callback, 2000).start() | |
| tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment