Skip to content

Instantly share code, notes, and snippets.

@Nekoyuki
Last active December 11, 2019 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nekoyuki/8c41c5d135f8b4b47d8f462381febffc to your computer and use it in GitHub Desktop.
Save Nekoyuki/8c41c5d135f8b4b47d8f462381febffc to your computer and use it in GitHub Desktop.
python / multiprocessing test in case a function has multi arguments.
from multiprocessing import Pool
import os
import time
start = time.time()
def func(n, a1, a2):
time.sleep(0.1)
r = n * a1 + a2
print('time:{:1.16f} r:{:5d} pid:{}'.format(time.time() - start, r, os.getpid()))
return r
def wrapper(args):
return func(*args)
if __name__ == '__main__':
process = 3
lst = [(i, 2, 5) for i in range(10)]
p = Pool(process)
output = p.map(wrapper, lst)
print(process)
print(time.time() - start)
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment