Python Watchdog Runs More Than Once
I am trying to learn python-watchdog, but I am sort of confused why the job I set up runs more than once. So, here is my set up: #handler.py import os from watchdog.events import F
Solution 1:
To debug watchdog scripts, it is useful to print what watchdog is seeing as events. One file edit or CLI command, such as touch
, can result in multiple watchdog events. For example, if you insert a print statement:
classChangeHandler(FileSystemEventHandler):
defon_any_event(self, event):
print(event)
to log every event, running
% touch job.done
generates
2014-12-24 13:11:02 - <FileCreatedEvent:src_path='/home/unutbu/tmp/job.done'>
2014-12-24 13:11:02 - <DirModifiedEvent:src_path='/home/unutbu/tmp'>
2014-12-24 13:11:02 - <FileModifiedEvent:src_path='/home/unutbu/tmp/job.done'>
Above there were two events with src_path
ending in job.done
. Thus,
ifgetext(event.src_path) == '.done':
run_something()
runs twice because there is a FileCreatedEvent
and a FileModifiedEvent
.
You might be better off only monitoring FileModifiedEvent
s.
Post a Comment for "Python Watchdog Runs More Than Once"