Skip to content

Instantly share code, notes, and snippets.

@OlegJakushkin
Created August 2, 2020 08:31
Show Gist options
  • Save OlegJakushkin/57b72c2188be7dead214bfb5198c0b6d to your computer and use it in GitHub Desktop.
Save OlegJakushkin/57b72c2188be7dead214bfb5198c0b6d to your computer and use it in GitHub Desktop.
import multiprocessing
from math import *
def chunks(l, n):
return [l[i:i+n] for i in range(0, len(l), n)]
def f(x):
print(x)
result = 0
for i in x:
print(i)
result +=i
return result
def handler(data, job_number):
p = multiprocessing.Pool(job_number)
total = len(data)
chunk_size = ceil(total / job_number)
slice = chunks(data, chunk_size)
r=p.map(f, slice)
return r
if __name__ == '__main__':
data = range(0,11)
result = handler(data, 2)
print(result)
@OlegJakushkin
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment