Created
July 12, 2017 11:04
-
-
Save gautamkrishnar/e09d78619e36db3aa1ce01022b43b184 to your computer and use it in GitHub Desktop.
simple program to do python multiprocessing
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
import multiprocessing as mp | |
process_list = [] | |
def pr1(test,test1): | |
""" | |
@:param: test,test1 (Integer) | |
process 1 | |
""" | |
print("Pr 1 prining... '"+str(test)+"','"+str(test1)+"' recieved...") | |
def pr2(): | |
""" | |
process 2 | |
""" | |
print("Pr2 2 prining...") | |
def pr3(): | |
""" | |
process 3 | |
""" | |
print("Pr3 3 prining...") | |
def initprocess(function_name,args=()): | |
""" | |
@:param function_name: name of the function | |
@:param arg: Arguments to pass to function (tuple) | |
Init processes and add it to the process list | |
t""" | |
global process_list | |
if args == (): | |
process_list.append(mp.Process(target=function_name)) | |
else: | |
process_list.append(mp.Process(target=function_name,args=args)) | |
return | |
def run(): | |
global process_list | |
for process in process_list: | |
process.start() | |
process.join() | |
def main(): | |
initprocess(pr1,(1,2,)) #Function with arguments | |
initprocess(pr2) #Function without arguments | |
initprocess(pr3) | |
run() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment