我正在开发一个简单的看门狗脚本,它将在上传到我们的 FTP 的一些非常大的图像上运行 md5sum。看门狗似乎没有 pyinotify 中存在的 IN_CLOSE_WRITE 事件。我尝试检查文件是否仍作为解决方法打开,但这不起作用。有谁知道从看门狗获取 close_write 事件的解决方法?
import sys
import time
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
path = sys.argv[1]
class MyEventHandler(FileSystemEventHandler):
def on_modified(self, event):
print "File uploaded"
# Is file still uploading?
f = open(event.src_path)
if f.closed:
print "....run md5 & email admin"
event_handler = MyEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()