Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to exit a function from another function?

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()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading