Skip to content

Instantly share code, notes, and snippets.

@bhpayne
Last active April 9, 2019 20:36
Show Gist options
  • Save bhpayne/97dee2d952efc4c02a33d6c11c5e0142 to your computer and use it in GitHub Desktop.
Save bhpayne/97dee2d952efc4c02a33d6c11c5e0142 to your computer and use it in GitHub Desktop.
Python 3 multiprocessing pool
# 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