Last active
June 3, 2020 06:17
-
-
Save bachkukkik/f928ed79617057cd5079e2f3ff81b314 to your computer and use it in GitHub Desktop.
kukkik python snippet
This file contains 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 | |
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