Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create a queue for our processing
- queue = Queue.Queue()
- class mRequests(threading.Thread):
- def __init__(self, queue):
- super(mRequests, self).__init__()
- self.queue = queue
- def run(self):
- while True:
- # Grab a url from our queue and make the call.
- my_site = self.queue.get()
- url = urllib2.urlopen(my_site)
- # Grab a little data to make sure it is working
- print url.read(1024)
- # Send the signal to indicate the task has completed
- self.queue.task_done()
- def input():
- for _ in range(4):
- t = mRequests(queue)
- t.setDaemon(True)
- # Start the thread
- t.start()
- try:
- for site in my_sites:
- queue.put(site)
- queue.join()
- except Exception:
- sys.exit(1)
- print mRequests.input()
Advertisement
Add Comment
Please, Sign In to add comment