一个简单的实现可以是:
import os.pathimport timewhile not os.path.exists(file_path): time.sleep(1)if os.path.isfile(file_path): # read fileelse: raise ValueError("%s isn't a file!" % file_path)每次检查后,您都需要等待一段时间,然后在路径存在时读取文件。
KeyboardInterruption如果从未创建该文件,则可以停止该脚本,但有例外。您还应该检查该路径是否位于该文件之后,以避免某些不必要的异常。



