I have a Python
function that acts as a "listener" for a file to be added to a folder (from an external process).
I am currently doing this using an infinite loop where I check for the file size to stop increasing (signifying that the file has finished being placed in the folder, and the rest of the python function can go on to open the file).
file_size = 0
while True:
file_info = os.stat(file_path)
if file_info.st_size == 0 or file_info.st_size > file_size:
file_size = file_info.st_size
sleep(1)
else:
break
This works, but I know its a hack. Polling an increasing file_size every one second doesn't seen like the best way to do this.
Is there another way to use Python
to determine if an file copy (from an external process) has completed?