Skip to content

Instantly share code, notes, and snippets.

@gautamkrishnar
Created July 12, 2017 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gautamkrishnar/e09d78619e36db3aa1ce01022b43b184 to your computer and use it in GitHub Desktop.
Save gautamkrishnar/e09d78619e36db3aa1ce01022b43b184 to your computer and use it in GitHub Desktop.
simple program to do python multiprocessing
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