Created
September 23, 2020 14:08
-
-
Save kissgyorgy/f087141cdf87dc4d42a3c65032ae83c1 to your computer and use it in GitHub Desktop.
Python: Makes your CPU sweat
This file contains hidden or 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
from concurrent.futures import ProcessPoolExecutor, wait | |
WORKERS = 6 | |
futures = [] | |
def cpu_hog(): | |
print("Starting computation") | |
return 2 ** 10000000000000000 | |
with ProcessPoolExecutor(max_workers=WORKERS) as exe: | |
print("Submitting compute-intensive jobs") | |
for _ in range(WORKERS - 1): | |
futures.append(exe.submit(cpu_hog)) | |
print("Waiting for processes to finish", flush=True) | |
wait(futures) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment