Created
August 2, 2020 08:31
-
-
Save OlegJakushkin/57b72c2188be7dead214bfb5198c0b6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo https://ideone.com/yiLCme