Я пытаюсь использовать Watchdog в python для мониторинга изменений файла.Но каждый раз, когда событие вызывается дважды. Я также пытался изменить событие, но оно не сработало, и оно вызвало событие дважды.
class MyHandler(PatternMatchingEventHandler):
patterns = ["myfile.TXT"]
def process(self, event):
"""
event.event_type
'created' | 'moved' | 'deleted'
event.is_directory
True | False
event.src_path
path/to/observed/file
"""
print(event.src_path, event.event_type)
def on_created(self, event):
self.process(event)
# self.process(event)
time.sleep(25)
historicalSize = -1
while (historicalSize != os.path.getsize(event.src_path)):
historicalSize = os.path.getsize(event.src_path)
print ('historicalSize', historicalSize)
# time.sleep(10)
start = time.time()
print("Copy start")
time.sleep(5)
copyfile(src, dst)
print("file copy has now finished")
timed = '{:.1f}'.format(time.time() - start)
print(' time:', timed)