Skip to content

Instantly share code, notes, and snippets.

@rootVIII
Created September 1, 2025 01:20
Show Gist options
  • Select an option

  • Save rootVIII/bb97bb120b5783a71f6f05492bfeb43a to your computer and use it in GitHub Desktop.

Select an option

Save rootVIII/bb97bb120b5783a71f6f05492bfeb43a to your computer and use it in GitHub Desktop.
Python example thread pool executor
from concurrent.futures import ThreadPoolExecutor, as_completed
from random import randint
from time import sleep
def task():
sleep_time = randint(1, 10)
print(f'sleeping {sleep_time}')
sleep(sleep_time)
return 5 * 5
def task_master(arr):
total = 0
with ThreadPoolExecutor() as executor:
for future in as_completed([executor.submit(func) for func in arr]):
total += future.result()
return total
if __name__ == '__main__':
res = task_master([task, task, task, task])
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment