Skip to content

Instantly share code, notes, and snippets.

@sunilmallya
Created August 21, 2013 20:09
Show Gist options
  • Save sunilmallya/6299539 to your computer and use it in GitHub Desktop.
Save sunilmallya/6299539 to your computer and use it in GitHub Desktop.
tornado multiprocessing async httpclient
#Pseduo python code
class HttpDownload(object):
def __init__(self,job,ioloop):
self.ioloop = ioloop
#create async http request
self.http_client = tornado.httpclient.AsyncHTTPClient()
self.http_client.fetch(self.req, self.async_callback)
def async_callback(self,reponse):
self.ioloop.stop()
#i am done
class Worker(multiprocessing.Process):
def run(self):
while not self.kill_received:
job = get_http_url()
ioloop = tornado.ioloop.IOLoop.current()
HttpDownload(job, ioloop)
ioloop.start()
if __name__ == "__main__":
for k in range(n):
# spawn workers
worker = Worker()
worker.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment