Created
May 23, 2020 16:42
-
-
Save rubentea16/61b22f091b71277ca3b2a90628ae7cb1 to your computer and use it in GitHub Desktop.
multipreprocessing technique
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 | |
| start = time.perf_counter() | |
| def do_something(seconds): | |
| print(f'Sleeping {seconds} second(s)...') | |
| time.sleep(seconds) | |
| return f'Done Sleeping...{seconds}' | |
| with concurrent.futures.ProcessPoolExecutor() as executor: | |
| secs = [3, 3, 3] | |
| results = executor.map(do_something, secs) | |
| for result in results: | |
| print(result) | |
| 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