Skip to content

Instantly share code, notes, and snippets.

@mildocjr
Created June 29, 2019 20:13
Show Gist options
  • Select an option

  • Save mildocjr/b44a1775570a5e1662cf8a028e154736 to your computer and use it in GitHub Desktop.

Select an option

Save mildocjr/b44a1775570a5e1662cf8a028e154736 to your computer and use it in GitHub Desktop.
multiprocessing1.py
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