Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created September 23, 2020 14:08
Show Gist options
  • Save kissgyorgy/f087141cdf87dc4d42a3c65032ae83c1 to your computer and use it in GitHub Desktop.
Save kissgyorgy/f087141cdf87dc4d42a3c65032ae83c1 to your computer and use it in GitHub Desktop.
Python: Makes your CPU sweat
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