Skip to content

Instantly share code, notes, and snippets.

@bachkukkik
Last active June 3, 2020 06:17
Show Gist options
  • Save bachkukkik/f928ed79617057cd5079e2f3ff81b314 to your computer and use it in GitHub Desktop.
Save bachkukkik/f928ed79617057cd5079e2f3ff81b314 to your computer and use it in GitHub Desktop.
kukkik python snippet
import concurrent.futures
import time
start = time.perf_counter()
def do_something(seconds):
print(f'Sleeping {seconds} second(s)...')
time.sleep(seconds)
return 'Done Sleeping...'
# with concurrent.futures.ProcessPoolExecutor() as executor: ### multiprocessing
with concurrent.futures.ThreadPoolExecutor() as executor: ### threading
lst_sec = [5,4,3,2,1]
results = executor.map(do_something, lst_sec)
lst_res = [r for r in results]
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} second(s)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment