我写了一个简单的脚本来更新我的CSS样式(从less到CSS),每次我更改less文件。我现在有:
import time
import hashlib
from subprocess import call
def md5_checksum(filePath):
fh = open(filePath, 'rb')
m = hashlib.md5()
m.update(fh.read())
fh.close()
return m.hexdigest()
md5 = md5_checksum('styles.less')
while True:
newmd5 = md5_checksum('styles.less')
if md5 != newmd5:
sh = open('styles.css', 'w')
call(['lessc', 'styles.less'], stdout=sh)
md5 = newmd5
sh.close()
print 'Changed'
time.sleep(0.2)
奇怪的是,脚本已经运行了一段时间:
^{pr2}$怎么回事?文件仍在那里100%。我做错什么了?在
正如Martijn Pieters所指出的,当im在文本编辑器中编辑较少的文件时,会有一段时间文件不存在(在保存期间,当旧文件被新文件替换时)。在
从strace记录(strace-o原木维姆样式。少):
因此,可能的解决方案是增加:
^{pr2}$或者,更好的方法是使用指向那里的方法:How do I watch a file for changes?。在
相关问题 更多 >
编程相关推荐