Created
August 21, 2013 20:09
-
-
Save sunilmallya/6299539 to your computer and use it in GitHub Desktop.
tornado multiprocessing async httpclient
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
#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