Skip to content

Instantly share code, notes, and snippets.

@yuliji
Created July 4, 2022 04:02
Show Gist options
  • Save yuliji/16e864ae049cde6cee4e6a8a4254bf3a to your computer and use it in GitHub Desktop.
Save yuliji/16e864ae049cde6cee4e6a8a4254bf3a to your computer and use it in GitHub Desktop.
[python process pool]
import multiprocessing
import time
def cube(x):
return x**3
if __name__ == "__main__":
pool = multiprocessing.Pool(3)
start_time = time.perf_counter()
processes = [pool.apply_async(cube, args=(x,)) for x in range(1,1000)]
result = [p.get() for p in processes]
finish_time = time.perf_counter()
print(f"Program finished in {finish_time-start_time} seconds")
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment