I want to run 2 functions at the same time. Then wait until those 2 functions are over, and it can start processing the rest of codes. I tried to use thread module but it just continue running without waiting those 2 functions finished. My example codes are as below:
import os, sys
import threading
from threading import Thread
class Example():
def __init__(self):
self.method_1()
def method_1(self):
for i in range(3):
print ('new')
def run(self):
threading.Thread(target = function_a, args=(self,)).start()
threading.Thread(target = function_b, args=(self,)).start()
def function_a(self):
for i in range(10):
print (1)
def function_b(self):
for i in range(10):
print (2)
run(self)
Example()
If the above codes get executed, the print ("new") inside method_1 will just print out immediately even before the function_a and function_b are over in each round of the for i in range(3). However, what I want is that the new will only be printed out as function_a and function_b are finished printing 1 and 2.
That is, the codes should stop at threading and wait for the function_a and function_b to finish so that it can continue processing the next i in the for i in range(3).
If anyone know how to solve this, please let me know. Appreciated!!