I am new to Python
I have the codes below:
Inside my for there is another for loop then that 2nd for loop calls a function that does another for loop. Now I want the 2nd for loop to wait until the 3rd loops finish its job. How to do that?
Thanks
def GetArea(img):
os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Process")
for file2 in glob.glob("*.png"):
# DO SOMETHING
# TAKE SOMETIME TO FINISH HERE.
-----------------------------------------------------------
for x in range(1, 2):
os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Area")
for file in glob.glob("*.png"):
img = cv2.imread(file, 0)
GetArea(img)
By default python runs synchronously (this is true of nearly all programming languages). This means that any statement will completely finish before the next statement begins. You would have to go out of your way to change this behavior.
As an aside: you have a problem where you refer to x inside your function but it is not passed in. This might work at the moment, because x is being treated as a global variable, but it would be more appropriate to let your function accept it, or to change your glob.glob invocation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With