if __name__ == '__main__':
    pool = Pool(39)
for result in pool.imap(f, itertools.product(pairs, repeat=16)):
    pass
Python itertools with multiprocessing - huge list vs inefficient CPUs usage with iterator