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

Does not appear to work on Macbook Pro with M2 (ARM) silicon? #47

Open
sharpe5 opened this issue Apr 18, 2024 · 6 comments
Open

Does not appear to work on Macbook Pro with M2 (ARM) silicon? #47

sharpe5 opened this issue Apr 18, 2024 · 6 comments

Comments

@sharpe5
Copy link

sharpe5 commented Apr 18, 2024

I ran watchdog on my Macbook Pro (2023) and it was not generating file change events. Same code worked perfectly on Debian. This library uses macfsevents behind the scenes.

Here is a script that runs macfsevents to reproduce the issue on my Macbook Pro:

import os
from pathlib import Path
from time import sleep
from fsevents import Observer, Stream, FileEvent # pip install macfsevents


def file_event_callback(file_event):
    print("File changed:", file_event.name)


path = Path(os.getcwd()) / 'test.txt'
if not path.exists():
    raise Exception(f'Error. File {path} does not exist.')
observer = Observer()
observer.start()
stream = Stream(file_event_callback, str(path), file_events=True)
observer.schedule(stream)

try:
    while True:
        sleep(1)
except KeyboardInterrupt:
    observer.stop()

To test, edit the file test.txt and look for the file changed event.

@malthe
Copy link
Owner

malthe commented Apr 18, 2024

Running on my M1, I'm seeing a number of test failures in PathObservationTestCase as well. It would be good to get an automated test run set up for MacOS on ARM.

@sharpe5
Copy link
Author

sharpe5 commented Apr 18, 2024

That would be great. As a workaround, I've used a shell script with tail to observe changes to the file in question.

@malthe
Copy link
Owner

malthe commented Apr 20, 2024

Looking through this again, first an observation that I don't think this library is particularly well put together (sadly).

That said, the problem you're experiencing is that you can't watch a file using file_events=True. It has to be a directory. If you wanted to watch a particular file, you can do so using flags=FS_CFLAGFILEEVENTS (which is then incompatible with the file_events option).

I don't really understand why the file_events option exists, but perhaps FS_CFLAGFILEEVENTS – which maps to the kFSEventStreamCreateFlagFileEvents flag – didn't work well at the time?

The documentation says:

Request file-level notifications. Your stream will receive events about individual files in the hierarchy you're watching instead of only receiving directory level notifications. Use this flag with care as it will generate significantly more events than without it.

But that is what you'd expect from file_events, too, so why does it exists? Not sure :-)

Finally, I don't think this is a problem with ARM vs Intel.

@sharpe5
Copy link
Author

sharpe5 commented Apr 20, 2024 via email

@malthe
Copy link
Owner

malthe commented Apr 21, 2024

Now, reading the documentation I realize that file_events=True gives you a number of virtual events that are compatible with inotify on Linux:

# inotify event flags
IN_MODIFY = 0x00000002
IN_ATTRIB = 0x00000004
IN_CREATE = 0x00000100
IN_DELETE = 0x00000200
IN_MOVED_FROM = 0x00000040
IN_MOVED_TO = 0x00000080

That said, yes as you suggest, using either file_events or flags=FS_CFLAGFILEEVENTS (which should be more efficient), you can listen to all events occurring under the provided directory path and then simply filter for the file you're interested in.

@sharpe5
Copy link
Author

sharpe5 commented Apr 21, 2024

Nice work! I'm working in this area for the next week so I can test any beta versions.

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

No branches or pull requests

2 participants