Created
July 4, 2022 04:02
-
-
Save yuliji/16e864ae049cde6cee4e6a8a4254bf3a to your computer and use it in GitHub Desktop.
[python process 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
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