def imap_unordered(pool, f, iterable): from collections import deque q = deque() # would be better to use the number of processes # actually in the pool MAX = multiprocessing.cpu_count() * 3 for arg in iterable: while len(q) >= MAX: yield q.popleft().get() q.append(pool.apply_async(f, (arg,))) while q: yield q.popleft().get() def ident(i): return i if __name__ == "__main__": import multiprocessing N = 1000000 pool = multiprocessing.Pool(3) total = 0 for i in imap_unordered(pool, ident, xrange(N)): total += i pool.close() pool.join() print "got", total, "expected", N*(N-1)//2