The test below shows the issue...
It works properly on Windows but on Mac it fails saying that the only change it found is the creation of my0.txt
(when it should've also found the change for the creation of the dir_rec
and dir_rec/my1.txt
).
def test_watchdog_recursive(tmpdir):
import watchdog
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import os.path
class Handler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)
self.changes = []
def on_any_event(self, event):
self.changes.append(os.path.basename(event.src_path))
handler = Handler()
observer = Observer()
watches = []
watches.append(observer.schedule(handler, str(tmpdir), recursive=True))
try:
observer.start()
time.sleep(0.1)
tmpdir.join("my0.txt").write("foo")
tmpdir.join("dir_rec").mkdir()
tmpdir.join("dir_rec").join("my1.txt").write("foo")
expected = {"dir_rec", "my0.txt", "my1.txt"}
timeout_at = time.time() + 5
while not expected.issubset(handler.changes) and time.time() < timeout_at:
time.sleep(0.2)
if not expected.issubset(handler.changes):
raise AssertionError(
f"Did not find expected changes. Found: {handler.changes}"
)
finally:
for watch in watches:
observer.unschedule(watch)
observer.stop()
Thank you for the test case @fabioz :)
I'll dig into it ASAP.
Just curious: what version of watchdog? Did it work before?
I am having a lot of problems with FileSystemEventHandler as well. It works the first time, and then entirely stops working. No events detected.
The Pattern matting event handler also does not work. It never matches the pattern of the file name, presumably because it is getting the parent directory of the file, and not the file itself. I sometimes got the events to trigger with a pattern of ["*"].
Also, when I move a file into a watched path, I do not get an event from the file I moved, but only from .DS_Store.
For the record, I installed the requisite pyobjc libraries, and switched to FSEventsObserver2, and that is working splendidly.
This is on 10.15.7
Just curious: what version of watchdog? Did it work before?
I'm testing with the latest released version (v0.10.4
). I'm not sure if it worked before or not (I know it works when using the fallback to use the kqueue
-- but that's not really feasible on my case as it requires too many file descriptors).
Do you mind trying with 0.10.3 馃檹 ?
FWIW, I'm just (today) checking out watchdog and, using 0.10.4 (MacOS BigSur), could not get _any_ event notifications (regardless of recursion, files, or directory changes). Switching to 0.10.3 works immediately!
Thank you for this package - it looks like what I need!
Duplicate of #702.
Sorry about the delay... I just tested it here and as reported, it really works with 0.10.3.