我试图在一段时间后执行一个功能。 时间间隔由Ftp服务器记事本文件控制。 用户更新记事本文件,该文件在一段时间后更新时间间隔。 但它不起作用它在启动时读取记事本文件中的数据并且threading.timer使用旧时它不更新代码甚至我们改变了记事本文件中的数据
def Dataflow():
try:
ftp = FTP('Domain')
ftp.login('username', 'password')
ftp.cwd('/directory where notepad file is saved')
server_file='control.txt' #The Text file that will control the data flow
local_file=r'C:\Users\Public\flow.txt' #The Local location of file which will catch data
ftp.retrbinary('RETR ' + server_file , open(local_file, 'wb').write) # To download the Dataflow rate from the notepad in ftp server
local_file = open(r'C:\Users\Public\flow.txt','r')
temp_store = int(local_file.read(20)) #storing the data of notepad file in variable
local_file.close(); ftp.close()
return temp_store
except:
pass
def function():
do something
time = threading.timer(Dataflow(), function)
time.start()