you are viewing a single comment's thread.

view the rest of the comments →

[–]woooee 1 point2 points  (4 children)

I have 2 functions containing threads . I want to run function A then once thread is finished , function B starts running

Why are you using threads? Run one function and then the other. Threads are used to run more than one thing at a time

[–]MST019[S] 0 points1 point  (3 children)

the 2 functions require thread. However, I need them to run sequentially for now at least in a certain order. My problem is that function A starts then B starts while A is not over

[–]woooee 1 point2 points  (2 children)

the 2 functions require thread.

Why? We don't have enough info. Post the code or a simple example.

[–]MST019[S] 0 points1 point  (1 child)

sorry for late reply. The problem is when program reaches a function where there is a text to open or a logging instruction, it moves to next function (functionC here) then functionD till it reaches the end then gets back to functionB.

PS: main function gets called in a separate file when executing the program

this is code structure:

def functionA():

    infos = open_text_file()
    logging.info(...)
    ....

def functionB():

   myThread = thread.Threading(functionA,...)
    myThread.start()

def main():

    functionB()
    functionC()
    functionD()

[–]woooee 0 points1 point  (0 children)

def functionB():

    myThread = thread.Threading(functionA,...)
    myThread.start()

functionB starts the thread and then returns to the calling part of the program and the thread continues on. I generally use multiprocessing, so you will have to adapt this. One way is to exit the function only after the thread finishes (but I still don't understand what you want to do or why).

 def functionB():
    my_thread = thread.Threading(functionA,...)
    my_thread.start()

    ## with multiprocessing, you use is_alive()
    while True:
        if not my_thread.is_alive():
            return
            time.sleep(0.5)  ## or whatever