Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Last active September 5, 2021 05:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/c508894ad72932e174c83d64e866ab30 to your computer and use it in GitHub Desktop.
Save velotiotech/c508894ad72932e174c83d64e866ab30 to your computer and use it in GitHub Desktop.
multiprocessing in python
from multiprocessing import Process
def print_func(continent='Asia'):
print('The name of continent is : ', continent)
if __name__ == "__main__": # confirms that the code is under main function
names = ['America', 'Europe', 'Africa']
procs = []
proc = Process(target=print_func) # instantiating without any argument
procs.append(proc)
proc.start()
# instantiating process with arguments
for name in names:
# print(name)
proc = Process(target=print_func, args=(name,))
procs.append(proc)
proc.start()
# complete the processes
for proc in procs:
proc.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment