Last active
February 8, 2020 21:23
-
-
Save kaanberke/c1c94f9adc429a14490e0e5fffb1f64b to your computer and use it in GitHub Desktop.
Thread Pool Executor
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 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as_completed -> First finisher gets the medal..
wait -> Even if you finish first, you have to wait your turn..