Novice to threading here. I'm borrowing a lot of the code from this thread while trying to build my first script using threading/queue:
import threading, urllib2 import Queue import sys from PIL import Image import io, sys def avhash(url,queue): if not isinstance(url, Image.Image): try: im = Image.open(url) except IOError: fd=urllib2.urlopen(url) image_file=io.BytesIO(fd.read()) im=Image.open(image_file) im = im.resize((8, 8), Image.ANTIALIAS).convert('L') avg = reduce(lambda x, y: x + y, im.getdata()) / 64. hash = reduce(lambda x, (y, z): x | (z << y), enumerate(map(lambda i: 0 if i < avg else 1, im.getdata())), 0) queue.put({url:hash}) queue.task_done() def fetch_parallel(job_list): q = Queue.Queue() threads = [threading.Thread(target=avhash, args = (job,q)) for job in job_list[0:50]] for t in threads: t.daemon = True t.start() for t in threads: t.join() return [q.get() for _ in xrange(len(job_list))] In this case the job_list is a list of URLs. I've found that this code works fine when this list is equal to or less than 50, but it hangs when > 50. There must be something I'm fundamentally not understanding about how threading works?