On a Windows OS, I use a python script that open an image in paint, using:
os.system("start %s" % path)
User suppose to edit the image, save the changes and close the file.
I wish the program will wait in a loop till the file is close, and then continue to run.
I tried:
time.sleep(5)
while True:
try:
myfile = open(path, "r+")
except IOError:
continue
break
myfile.close()
It seems to break the loop also if I don't close the file. time.sleep(5) is to make sure the file got open successfully, and we don't have some timing issues.
Instead of myfile = open(path, "r+")
I tried to use os.rename()
, as someone advised here, but it does the opposite - stay in the loop even after I close the file.
It seems duplicate from here, but the solution there fits only for Excel files and I couldn't find an answer that fulfill my wish.
Thanks!