Last active
April 8, 2017 12:17
-
-
Save tonygaetani/6b4e93cd44878a8b9523 to your computer and use it in GitHub Desktop.
an example of concurrent.futures.ProcessPoolExecutor for python 2.7
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
import concurrent.futures | |
import time | |
def sleep_print_return(input): | |
print "{} started".format(input) | |
time.sleep(input % 3) | |
return input | |
def main(): | |
# to observe the difference, change max_workers to 1 | |
with concurrent.futures.ProcessPoolExecutor(max_workers=None) as executor: | |
for result in executor.map(sleep_print_return, range(25)): | |
# do stuff | |
print "{} finished".format(result) | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment