-
Notifications
You must be signed in to change notification settings - Fork 688
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
Modifed event triggered twice #93
Comments
Are you able to reproduce this issue with the current HEAD or v0.6.0? |
I can reproduce with HEAD. but i have some strange behaviour, the log command don't run twice, only occours in shell_command |
Same situation here as wsantos. Works great but this particular issue made watchdog useless for me. |
I'm encountering this as well. The I'm running 587cbee on Mavericks. |
I'll look into this. This has been an issue for quite some time. |
First order of business is to check if it's actually modified twice or not. E.g if you |
I'm having the same issue when using vim to edit files(with "set nobackup, nowritebackup") under Ubuntu 14.04. |
Was this issue resolved? I just resave the same file back to the disk without modifying it and it again triggers 2 events in my case. |
Perhaps it would be helpful to do a |
The same issue still exists i.e. on the creation of a new file the 'modified' event is called twice. |
I have the same issue here on Ubuntu 18.04 64bit: the |
I have the same issue. Can we please get that resolved? |
I also have this issue, and I think I found the problem. In elif event.is_modify:
cls = DirModifiedEvent if event.is_directory else FileModifiedEvent
self.queue_event(cls(src_path)) which uses the @property
def is_modify(self):
return self._mask & InotifyConstants.IN_MODIFY > 0 Notice that
So the solution is, I think, to expose both the |
Is this issue resolved? because I'm using watchdog 0.9.0, when i modify a .txt file through notepad in windows 10, on_modify methods gets call once or twice randomly. |
@anvesh1212 no, not resolved |
@Endogen any alternative solution? and when can we expect it to be resolved? |
@anvesh1212 I don't think it will ever be fixed. This issue is open since 2012. I go with the workaround that @naveenjafer posted on 25 Dec 2017. |
@anvesh1212 On Windows 10 it might be a slightly different issue. The library will provide a different implementation (WindowsApiObserver) when it detects that the platform is Windows. I was able to reproduce the issue 100% of the time on Windows 10 with the default import: from watchdog.observers import Observer However I no longer reproduce it by selecting the generic implementation: from watchdog.observers import PollingObserver as Observer This could be used as a workaround, although this class may not be guaranteed to be suitable in the future. |
This happens because you're defaulting back to the slow polling rather than relying on the windows filechange API. See more here: https://github.com/gorakhargosh/watchdog#supported-platforms As an aside I had to use Not convinced this would be suited for anything other than tens of files, it'll scale awfully with increasing complexity of file structures. It's a complicated issue to fix, though it makes it difficult for my use case - something akin to an npm watch command to monitor file changes for compilation of jinja2 templates. Interestingly, VScode has some peculiar but expected behaviour when saving - if the file is empty it's a single modification event, if it's saving with content it's two - assuming one is dumping the content after. Not much else to debug here other than some events will be duplicated and sometimes it could be by design. Edit: Found this and it works for the most part, but limits some things - https://stackoverflow.com/questions/18599339/python-watchdog-monitoring-file-for-changes just by virtue of having a second timeout to prevent duplicates. As an example: Running the following in WSL Bash
As such it's missing most of the events there - so there may be some scope to fix that because if a lot of files change at once it'll miss it rather than dropping duplicates. For comparison: Standard observer behaviour when I click save all on 4 modified files:
|
So I did some digging and found watchgod, and it handles this better albeit in a different way, opened 4 files in vscode, made a change and did save all running the following example:
resulting output:
It's definitely different but it's not duplicated so from my POV that's something I can work with - last thing I want to do is add a FIFO queue and dequeue system in to deduplicate these things prior to execution of a function on the file. Example 2:
All 26 files changed were shown in a single response. Tried the same with 1..1000 and all the files were in the same response, and added All in all it seems to work and it may help the people in this thread. Disclaimer: It's using file system polling, so it may not be efficient but the async support presented some perks against that backdrop. Performance comparison isn't that easy with an async function so I've not tried to wrap it in timeit, that being said, it may be useful to get a snapshot dictionary back of changes in a polling time delta rather than many itemised changes - depends on usecase. Note: Just tried it on Arch with linux 5.3 and it's ORDERS of magnitude faster than windows. For comparison, I switched to powershell natively with fsutil to create files and I couldn't even create files quick enough - on linux with bash parameter expansion on touch I could create, and get a dictionary of, 10000 files in less than a second. Can't confirm on MacOS but I can't think of a way to create many dummy files simultaneously on windows, a for loop with fsutil seems too slow, using WSL to use touch in bash suffers the NTFS translation layer IO performance penality - if anyone has a good suggestion there to create 1000 files on windows simultaneously for testing I'm all ears. |
if I copy and paste a file on OSX lion
it triggered created event once and modified event twice
should it be just trigger once modified event?
INFO:root:Created file: /Users/ouyangjichao/BoxSync/rename/testwatchdog.py INFO:root:Modified file: /Users/ouyangjichao/BoxSync/rename/testwatchdog.py INFO:root:Modified file: /Users/ouyangjichao/BoxSync/rename/testwatchdog.py
The text was updated successfully, but these errors were encountered: