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

No file system events observed when not using recursive mode #918

Open
cedrickring opened this issue Sep 16, 2022 · 5 comments · May be fixed by #1013
Open

No file system events observed when not using recursive mode #918

cedrickring opened this issue Sep 16, 2022 · 5 comments · May be fixed by #1013

Comments

@cedrickring
Copy link

We tried to listen for events on a single file, without the need for watching recursively. However without specifying recursive=True, no events were observed.

Platform: macOS 12.6 & Ubuntu 18.04
Python: 3.9.14

Code to reproduce:

import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path)
    observer.start()
    try:
        while True:
            time.sleep(1)
    finally:
        observer.stop()
        observer.join()

and launching with: python file.py <path to single file>.

Also using the FSEventsObserver on macOS didn't change the outcome. Only specifying recursive=True did.

@kurtmckee
Copy link
Contributor

I don't think the underlying operating system calls support watching a single file -- the watchdog code and the underlying OS API's document that it's only supported to watch a directory.

While it may be possible to specify a file path without triggering an error, it's not supported.

@cedrickring
Copy link
Author

cedrickring commented Oct 19, 2022

I totally agree with your points. However, the docs should point out that you always need to watch recursively or just default to it on some machines...

@Rosuav
Copy link

Rosuav commented Oct 9, 2023

Agreed. I got bitten by this today; a script that worked absolutely fine on my Linux box (Debian Bullseye, inotify) utterly failed to report anything on my client's Mac. Setting recursive=True made it work. Having this be the default when using FSEvents would solve that issue.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Oct 9, 2023

I agree that recursive could be true by default for FSEvents. Anyone willing to chime in? I will be happy to review a PR :)

@Rosuav
Copy link

Rosuav commented Oct 9, 2023

I'll have a whack at it, but I don't have a Mac to test on, so all I can say is, the tests haven't started failing on Linux.

#1013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants