Skip to content

Instantly share code, notes, and snippets.

@tonygaetani
Last active April 8, 2017 12:17
Show Gist options
  • Save tonygaetani/6b4e93cd44878a8b9523 to your computer and use it in GitHub Desktop.
Save tonygaetani/6b4e93cd44878a8b9523 to your computer and use it in GitHub Desktop.
an example of concurrent.futures.ProcessPoolExecutor for python 2.7
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