I'm trying to understand multiprocessing in python.
from multiprocessing import Process
if __name__ == '__main__':
p = Process(target= multiply, args= (5,4))
Ok, i somehow managed this. I looked to python documentation, and i learnt that: with using Queue class, we can get return values from a function. And final version of my code is like this:
from multiprocessing import Process, Queue def multiply(a,b,que): #add a argument to function for assigning a queue que.put(a*b) #we're putting return value into queue if __name__ == '__main__': queue1 = Queue() #create a queue object p = Process(target= multiply, args= (5,4,queue1)) #we're setting 3rd argument to queue1 p.start() print(queue1.get()) #and we're getting return value: 20 p.join() print("ok.")
And there is also a pipe() function, i think we can use pipe function,too. But queue worked for me, now.