Comments (7)
What are you using to change the file? Does a simple touch
trigger this, or is this a program (which may have its own weird behaviour)?
from notify.
Thanks for the fast reply! :)
I was using Atom to change the files, just modifying and saving. I will try with touch and let you know if that changed anything.
from notify.
Yeah, oftentimes editors and programs have their own ways of saving/writing files, like they might save to a separate file and then rename it to the target file. For example, vim and emacs don't simply just write to the file directly from what I've observed. You'll notice touch by itself does do what you expect. You'll have to accommodate the way atom does it yourself.
Although it is indeed weird that you're receiving 4 writes to the same file for every write you say you make? Were you only printing out the write events, or were other events being triggered?
from notify.
Ah ok, thanks for the clarification!
In that case I will close the issue and keep my workaround :)
Thanks!
from notify.
No need to close it if what I said ended up not applying to your situation, since I can't be sure. It does seem weird that atom is creating that many write events, but then I'm not sure how atom works. One thing you can do to check though is like @passcod said, try using touch
on the file and you should see what you expect, a single event. That will rule out your code being the problem; I doubt your code is the problem.
Honestly recursing like you are in your workaround doesn't seem very sound. I think it's creating separate "inotify instances" so basically you get one event, you process it, then you create another inotify instance which means you start with a fresh "event queue" which is why you don't "get" the repeated events. I think a better approach would avoid recreating inotify instances (i.e. notify::Watcher::new
) and instead introduce perhaps some sort of debouncing logic to ignore repeated events within a certain short timespan, or something.
from notify.
I will just re-open if there is indeed a bug.
Honestly recursing like you are in your workaround doesn't seem very sound.
I know, what I am most afraid of is to hit the max recursion limit.. I should probably try to find a more clever solution like you said.
instead introduce perhaps some sort of debouncing logic to ignore repeated events within a certain short timespan
I agree, this would be a more robust solution. I am not sure however this would be trivial to implement in my case, because the action I do after a file changed takes a little time (± 1s). And as I understand it, the events are queued in the receiver until processed. So the time I would measure would not be the time between the events but the time it took the action to complete...
I tried to find a way to empty the receiver rx
, to clear all the events that happened while doing the task, but I didn't find any method for that in the std docs. Seems kind of weird that you can't flush it.
Do you have a solution?
from notify.
Maybe just recv
the events and then immediately discard them if you're processing the action? I do something similar in cargo-watch (which was the original reason for notify to exist).
from notify.
Related Issues (20)
- Watcher isn't Sync with --no-default-features HOT 1
- `bitflags` dependency for macos only?
- Debouncers don't implement Debug HOT 3
- Is there someway to make debounce-watcher be async? HOT 3
- release with bumped `bitflags` and `filetime` version HOT 2
- (even more) license clarifications: non-standard Artistic-2.0 license HOT 6
- Potential Double Free Issue HOT 2
- Use KqueueWatcher as RecommendedWatcher for iOS
- Breaking Changes v7 HOT 7
- notify crate not actually including license text HOT 2
- Catch no events after saving a watching file with Vim editor HOT 1
- How to write unit tests that exercise a watcher? HOT 3
- Filtering out `log` logs HOT 2
- 【with tokio】After executing `git checkout .` command and then modifying the file, unable to get response to file changes
- Advice for multiple watchers of the same path(s) HOT 2
- How do you dynamically observe files in a directory and log a new file as it appears HOT 1
- My program stops getting events after some time HOT 2
- Watch code is not run inside helper function HOT 2
- `notify-debouncer-full` / `-mini` always enable `notify` default features
- Proposal: Change the serialization format of events HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notify.