Skip to content

Instantly share code, notes, and snippets.

@tyjeon24
Last active June 7, 2021 14:32
Show Gist options
  • Save tyjeon24/e490949d71df7424db1c7ba7972253f8 to your computer and use it in GitHub Desktop.
Save tyjeon24/e490949d71df7424db1c7ba7972253f8 to your computer and use it in GitHub Desktop.
리스트 안의 것들을 multiprocessing으로 처리해서 저장해주는 기능.
import multiprocessing
import time
def square(result, x):
result.append(x*x)
if __name__ == "__main__":
# 1. Prepare multiprocessing
pool = multiprocessing.Pool(8)
m = multiprocessing.Manager()
result = m.list()
# 2. Prepare input list
input_values = [x for x in range(1, 10001)]
# 3. Run multiprocessing
start_time = time.time()
starmap_list = [(result, x) for x in input_values]
pool.starmap(square, starmap_list)
pool.close()
pool.join()
print(time.time() - start_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment