Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Multiple calls per watch event on linux with rb-inotify #98

jeffutter opened this Issue · 8 comments

6 participants


It seems that in some cases rb-inotify is generating multiple events when it should only be generating one.

My specific scenario:

I'm using the sublimetext editor. When saving a file with sublimetext it uses one fwrite operation and then multiple writes in 4k blocks.

as can be seen here:

Guard is watching for :close_write and :modify events. A modify event gets triggered for every 4k block written by the editor. If guard just listened for :close_write it would only trigger once when the editor has closed the file handle. I can't really think of any situation where :modify would be needed, but there may be some.


From the inotifywatch man page:

    A watched file or a file within a watched directory was written to.

    A watched file or a file within a watched directory was closed, after being opened
    in writeable mode. This does not necessarily imply the file was written to.

So when the editor writes a file in chunks, it fires several :modify and a single :close_write. So from my understanding, when removing :modify from the listener, we'll catch only the end of the write operation. However there may be other editors that keeps a file handle open and thus fires only :modify events.

I'm not sure how to approach this, since it may break another editor and I'm not using Linux on my development machine. I'd like to see more analysis of inotify events for other popular editors like vim, nano, joe, gedit, kate, SciTE, etc.


Here is the inotifywatch output from a few common editors. I opened the file, launched inotifywatch, changed it, saved it, killed inotify watch:

Sublime Text

total  modify  close_write  open  filename
5      3       1            1     coffee/


total  attrib  move_self  delete_self  filename
4      1       1          1            coffee/


total  access  attrib  close_write  close_nowrite  open  delete_self  filename
8      1       1       1            1              2     1            coffee/


total  modify  close_write  open  filename
5      3       1            1     coffee/


total  access  modify  attrib  close_write  close_nowrite  open  filename
10     1       4       1       1            1              2     coffee/


total  move_self  filename
1      1          coffee/


total  modify  close_write  open  filename
5      3       1            1     coffee/


total  attrib  close_write  open  filename
4      2       1            1     coffee/

echo 'foo' > coffee/test.txt

total  modify  close_write  open  filename
4      2       1            1     coffee/test.txt

It looks to me like everything has a close_write except for a few that have neither close_write nor modify. I think these ones write to a tmp file and then move it into place over the existing file.


Awesome job! I will take care of it tomorrow. Thanks a lot.


Seems like supporting only close_write & move_self (for vim & jedit) would cover 100% of editors listed above. Thanks these info, that's really helpful!


I'd like to add this issue, which is now closed, to this thread:

guard/guard-rspec#26 (comment)


Fixed in this commit

@thibaudgg thibaudgg closed this

With Kate 3.12 run_on_modifications is no longer being fired. Output from inotifywatch is:

total  attrib  delete_self  filename
3      1       1            catalogdetail.tpl

@onlineamateur Please report any listener issue directly in the Listen issue tracker since it's handled there now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.