Last active
April 9, 2019 20:36
-
-
Save bhpayne/97dee2d952efc4c02a33d6c11c5e0142 to your computer and use it in GitHub Desktop.
Python 3 multiprocessing pool
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
# Python3 | |
import multiprocessing | |
print(multiprocessing.cpu_count()) | |
def serial_function(some_variable): | |
reslt=some_variable*5 | |
return reslt | |
list_of_variables=[3, 5] | |
start_time = time.time() | |
if __name__ == '__main__': | |
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count()) # start worker processes | |
res_list=[] | |
for a_variable in list_of_variables: | |
res_list.append(pool.apply_async(serial_function, (a_variable))) | |
list_of_res = [res.get() for res in res_list] | |
print('elasped time:',time.time()-start_time,'seconds') | |
print(list_of_res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment