Python多处理不是异步的

时间:2017-08-31 16:57:14

标签: python multithreading multiprocessing

我正在使用这样的Python多处理:

pool = mp.Pool(processes=mp.cpu_count())
num_jobs = 5

print("Start Multiprocessing with: " + str(mp.cpu_count()) + " processes and " + str(num_jobs) + " jobs")

for i in range(num_jobs):
    start = int(...)
    end = int(...)
    result = pool.apply_async(worker, args = (parameter1, start, end, ), callback = callback_function)
    result.get()

result = pool.apply_async(worker2, args = (parameter1, parameter2, ), callback = callback_function2)
result.get()

pool.close()
pool.join()

在我的工作人员职能中,我打印得像:

def worker(parameter1, start, end):

    for in_idx in range(0,100)
        print(in_idx)

然而,工人被称为分段而非异步。这有什么不对?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

正如@jordanm所说:

  

默认阻止get()直到完成。