在执行某些代码之前等待条件为真的最有效方法是什么?例如,我只想在修改文件时执行代码。我的代码在'white True:'循环中。我不确定这是否是最好的事情,或者这是否是常见做法,因为'while True:'循环不断循环并耗尽cpu。我可以在那里写一个暂停声明,但我想知道什么是事实上这样做的方法?在等待条件成立时,脚本需要持续运行。
while True:
modTime = os.path.getmtime('C:\\example1.xlsx')
if(modTime > curTime):
#execute code
#execute code
#execute code
curTime = modTime