在多次迭代中,报告从其他位置传输的大文件的文件大小错误或相同。
目标:要通过跟踪大小来检查文件是否在增长,如果文件大小稳定,则可以启动/执行文件上的其他功能。
import os,sys,time
MAXCHECKCOUNT = 6
def checkgrow(filepath):
oldfilesize = -1
tries = 0
while True:
#to reset
filesize = os.stat(filepath).st_size
# filesize = readFile(filepath)
print (filesize)
if oldfilesize == filesize:
# time.sleep(1)
if tries >= MAXCHECKCOUNT:
print("file not growing anymore")
break
else:
print ("trying for %d time" %(tries))
tries += 1
else:
tries=0
oldfilesize = filesize
def readFile(filepath):
filesize = 0
with open(filepath) as handle:
handle.seek(0,os.SEEK_END)
filesize = handle.tell()
return filesize
观察: