Created
June 29, 2019 20:13
-
-
Save mildocjr/b44a1775570a5e1662cf8a028e154736 to your computer and use it in GitHub Desktop.
multiprocessing1.py
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 multiprocessing | |
| import time | |
| numbers = range(100000, 1000000, 10000) | |
| def task(number): | |
| print(f"Executing new Task with process {multiprocessing.current_process().pid}") | |
| result = 0 | |
| for i in range(number): | |
| result = result + i | |
| print(f"Result: {result}") | |
| print(f"Task Executed with process {multiprocessing.current_process().pid}") | |
| def main(): | |
| executor = multiprocessing.Pool(processes=1) | |
| executor.map(task, numbers) | |
| executor.close() | |
| if __name__ == "__main__": | |
| start_time = time.time() | |
| main() | |
| print("\n\nCOMPLETE\n--- Took %s seconds ---" % (time.time() - start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment