Skip to content

Instantly share code, notes, and snippets.

@kaanberke
Last active February 8, 2020 21:23
Show Gist options
  • Select an option

  • Save kaanberke/c1c94f9adc429a14490e0e5fffb1f64b to your computer and use it in GitHub Desktop.

Select an option

Save kaanberke/c1c94f9adc429a14490e0e5fffb1f64b to your computer and use it in GitHub Desktop.
Thread Pool Executor
from concurrent.futures import ThreadPoolExecutor
from time import sleep
def overself(n):
print(f'In overself function for {n}')
sleep(2)
return n ** n
def main(values):
with ThreadPoolExecutor(max_workers = 5) as executor:
results = executor.map(overself, values)
for result in results:
print(result)
if __name__ == '__main__':
values = [5, 7, 9, 11]
main()
@kaanberke
Copy link
Author

as_completed -> First finisher gets the medal..
wait -> Even if you finish first, you have to wait your turn..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment