fork(1) download
  1. import multiprocessing
  2. from math import *
  3. def chunks(l, n):
  4. return [l[i:i+n] for i in range(0, len(l), n)]
  5.  
  6. def f(x):
  7. print(x)
  8. result = 0
  9. for i in x:
  10. print(i)
  11. result +=i
  12. return result
  13.  
  14. def handler(data, job_number):
  15. p = multiprocessing.Pool(job_number)
  16. total = len(data)
  17. chunk_size = ceil(total / job_number)
  18. slice = chunks(data, chunk_size)
  19. r=p.map(f, slice)
  20. return r
  21.  
  22. if __name__ == '__main__':
  23. data = range(0,11)
  24. result = handler(data, 2)
  25. print(result)
Success #stdin #stdout 0.06s 15508KB
stdin
Standard input is empty
stdout
[15, 40]
range(0, 6)
0
1
2
3
4
5
range(6, 11)
6
7
8
9
10