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

on_modify called every couple of milliseconds on ubuntu #280

Closed
ehmo opened this issue Oct 17, 2014 · 5 comments
Closed

on_modify called every couple of milliseconds on ubuntu #280

ehmo opened this issue Oct 17, 2014 · 5 comments

Comments

@ehmo
Copy link

ehmo commented Oct 17, 2014

I have absolutely different behavior for the same code on Mac vs Ubuntu.

I am using the example code

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 = '/tmp'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

On Mac, the result is what I was expecting

2014-10-17 14:45:07 - Created file: /tmp/test.test
2014-10-17 14:45:07 - Modified directory: /tmp
2014-10-17 14:45:08 - Modified file: /tmp/test.test

But the same code on ubuntu is triggered every couple of milliseconds even I didn't change anything in the code.

2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test
2014-10-17 21:57:35 - Modified file: /tmp/test.test

I was looking for some on_close statement, but nothing is there thus I thought that on_modified is triggered when the file is closed. But it seems like it only works that way on Mac not on ubuntu.

Any idea what to do?

@ehmo ehmo changed the title on_modify called every couple o milliseconds on ubuntu on_modify called every couple of milliseconds on ubuntu Oct 17, 2014
@tamland
Copy link
Collaborator

tamland commented Oct 29, 2014

on_modified is triggered on write. On osx the modified events are generated by comparing mtime (which only have 1 second resolution on osx if I recall correctly) so this is normal.

@ehmo
Copy link
Author

ehmo commented Oct 30, 2014

@tamland well, that's strange as on_modified is triggered on OS X only when the file is closed, not when it's being written.

If this is all is true, what event tells me that the file was just closed by all processes and can be accessed? In inotify it's IN_CLOSE_WRITE

@tamland
Copy link
Collaborator

tamland commented Oct 30, 2014

Might be an issue with triggering the event generation. When you say it like that is sounds a lot like it could be the cause of some other vague issues reported #126 (bottom), #258

There's currently no IN_CLOSE-like event implemented (tl;dr: it's impossible to do that cross-platform. See #217)

@ehmo
Copy link
Author

ehmo commented Nov 1, 2014

Hm, if there is no IN_CLOSE event implemented, it's probably not possible for me to use watchdog. If I have to monitor watchdog itself, then it just ads extra work and then it's easier to use Launchctl on Mac and Inotify on Linux.

Thanks anyway

@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 15, 2021

Finally implemented the inotify event with 2fab7c2 (will be part of the 1.0.3 version).

@BoboTiG BoboTiG closed this as completed Jan 15, 2021
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

3 participants