python multiprocessing passing of variable

Viewed 30

I am trying to pass a value from one function to another but it seems its not doing so. here is my code:

x = 0
y = 1

def funcTwo():
    global x,y
    
    while x < 3:
        x = x + 1
        print('this is x= ' + str(x))
        time.sleep(1)
        if x == 3:
            x = 0
            
def funcOne():
    global x,y
    while y < 4:
        y = x + y
        print('this is y= '+str(y))
        time.sleep(1)
        if y == 4:
            y = 1


    
if __name__ == "__main__":
    
                
    def runInParallel(*fns):
        proc = []
        for fn in fns:
            p = Process(target=fn)
            p.start()
            proc.append(p)
        for p in proc:
            p.join() 
    
 runInParallel(funcOne, funcTwo)

the variable x is not moving to the second function? is there a need to return the variable x or something ?

0 Answers
Related