Skip to content

Instantly share code, notes, and snippets.

@dlukes
Created February 27, 2017 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlukes/4d73a03d64b324ab59e4815b8d868240 to your computer and use it in GitHub Desktop.
Save dlukes/4d73a03d64b324ab59e4815b8d868240 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import time
import subprocess as sp
import concurrent.futures as cf
start = time.time()
with cf.ThreadPoolExecutor() as e:
futures = [e.submit(sp.check_output, f"sleep 2s && echo Done {i}.", shell=True) for i in range(3)]
for future in cf.as_completed(futures):
print(future.result())
end = time.time()
print(f"The whole thing took {end-start} seconds.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment