Last active
December 11, 2019 13:52
-
-
Save Nekoyuki/8c41c5d135f8b4b47d8f462381febffc to your computer and use it in GitHub Desktop.
python / multiprocessing test in case a function has multi arguments.
This file contains 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
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