所以我正在监控大量文件的修改时间。文件更新后,我通过 ssh 将其复制到另一台机器。这是我所拥有的SSCCE:
import os
import time
send = "/home/pi/PythonScripts/tempData.txt"
check = "/home/pi/PythonScripts/check.txt"
statbuf = os.stat(send)
print "Modification time:",statbuf.st_mtime
def wr2(data):
file2 = open(check, 'w')
file2.write(str(data))
file2.close()
return 0
def rd():
file = open(send, 'r')
line2 = file.readline()
file.close()
return line2
def rd2():
file2 = open(check, 'r')
line2 = file2.readline()
file2.close()
return line2
while(run):
try:
statbuf = os.stat(send)
line2 = rd2()
print line2
if (str(statbuf.st_mtime) == line2):
print "File has not changed...\n"
time.sleep(1)
else:
data = rd()
print "Data in File: " + data
os.system("sudo scp /home/pix/PythonScripts/tempData.txt server1:/home/tix/Server1_SSH/Real_Data.txt")
wr2(statbuf.st_mtime)
print "New Modification Time:",statbuf.st_mtime
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
print '\nKeyboard Interrupt Caught!'
run = 0
raise
因此,当它到达os.system()
命令时它挂在那里没有做任何事情......但是当我在 python 解释器上运行相同的确切代码时,它工作得很好。我似乎无法理解问题是什么......任何帮助都会很棒!