دنبال کننده ها

۱۳۹۶ شهریور ۹, پنجشنبه

multithreading - Python multiprocessing is not asynchron

[ad_1]



I am using Python multiprocessing like this:



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()


In my worker functions I print sth like:



def worker(parameter1, start, end):

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


However, the workers are called segmentally rather than asynchronously. What is wrong here? Any ideas?




[ad_2]

لینک منبع