Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdog on Mac OS not tracking new dirs when recursively listening for changes #706

Closed
fabioz opened this issue Nov 29, 2020 · 8 comments
Closed

Comments

@fabioz
Copy link

fabioz commented Nov 29, 2020

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()
@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 1, 2020

Thank you for the test case @fabioz :)
I'll dig into it ASAP.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 2, 2020

Just curious: what version of watchdog? Did it work before?

@mwdiers
Copy link

mwdiers commented Dec 2, 2020

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

@fabioz
Copy link
Author

fabioz commented Dec 3, 2020

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).

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 3, 2020

Do you mind trying with 0.10.3 🙏 ?

@kevin-bates
Copy link

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!

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 4, 2020

Duplicate of #702.

@BoboTiG BoboTiG closed this as completed Dec 4, 2020
@fabioz
Copy link
Author

fabioz commented Dec 7, 2020

Sorry about the delay... I just tested it here and as reported, it really works with 0.10.3.

CCP-Aporia added a commit to CCP-Aporia/watchdog that referenced this issue Dec 9, 2020
BoboTiG pushed a commit that referenced this issue Dec 9, 2020
* Remove spurious whitespace

* Expose missing fsevents properties

* Use PyCapsule with Python 2.7

Addresses one possible source of memory corruption, and simplifies the code.

* Fix event_id construction

* Ensure UTF-8 encoded paths are used

* Fix regression introduced by Utf8 conversion func

Python 2.7 didn't like the double string conversion.

Also improve some of the error handling code to behave better, as
well as add error handling to th PyCapsule creation.

* Add test for recursive watch

Inspired by issue #706

* Limit tox to Python versions supported in this branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants