multiprocessing

def task(pid):
    # do something
    return result

def main():
    multiprocessing.freeze_support()
    pool = multiprocessing.Pool()
    ntasks = 200;
    results = []
    for i in xrange(0, ntasks):
        result = pool.apply_async(task, args=(i,))
        results.append(result)
    pool.close()
    pool.join()

for result in results:
    print(result.get())

你可能感兴趣的:(multiprocessing)