Skip to content

Instantly share code, notes, and snippets.

@BibMartin
Created January 21, 2017 14:13
Show Gist options
  • Select an option

  • Save BibMartin/eb08cf972c33d5d2552274eaf2e3887f to your computer and use it in GitHub Desktop.

Select an option

Save BibMartin/eb08cf972c33d5d2552274eaf2e3887f to your computer and use it in GitHub Desktop.
A tornado web service that self-calls itself periodically
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