Last active
September 5, 2021 05:10
-
-
Save velotiotech/c508894ad72932e174c83d64e866ab30 to your computer and use it in GitHub Desktop.
multiprocessing in python
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
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