I want to exit a function in another function if statement is True. I am using multiprocessing so they are running concurrently.
I want to make something like this:
def A():
while True:
if condition is True:
#do something
else:
True
def B():
while True:
if condition is True:
#stop A() function
else:
True
def main():
p1 = multiprocessing.Process(target=A())
p2 = multiprocessing.Process(target=B())
p1.start()
p2.start()
p1.join()
p2.join()
if __name__ == '__main__':
main()
>Solution :
There are multiple synchronization primitives you could use, such as a condition variable:
You could use a mp.Condition() calling
while not predicate():
cv.wait()
in A() and notify() in B()