Hello!

This is my first post here, so hello everybody!


I'm in the process of writing a little python program that should monitor a certain number of text files, and update a database with changes from these files.

I have discovered that the fileChanged signal is abit unpredictable. On my development machine I'm running Linux, and I have a virtual windows machine to test the code for portability. The problem is that on my linux machine the fileChanged event triggers seven times for each time I save the file I'm watching. On the windows machine it triggers one(as expected). I suspect this might have to be because of differences in the filesystems (ext4/ntfs), but wanted to ask here in case anybody have had similar issues.

Just to be clear, the text files I'm monitoring will be written to by another application, and will contains hundred of thousands of lines. I'm queuing the events up in a threaded Queue handler to process the file changes in correct order, so it's not very efficient to process the same event multiple times =)

I've written a tiny example to square away all other possibilities.

Qt Code:
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3.  
  4. import sys
  5. from PyQt4 import QtCore
  6. from PyQt4 import QtGui
  7.  
  8. class FilesystemWatcher(QtCore.QFileSystemWatcher):
  9. def __init__(self, parent=None):
  10. QtCore.QFileSystemWatcher.__init__(self, parent)
  11.  
  12. path = "/home/rolf/Desktop/Driver2.dat"
  13. self.addPath(path)
  14.  
  15. self.connect(self, QtCore.SIGNAL("fileChanged(const QString&)"), self.fileChangedSlot)
  16.  
  17.  
  18. def fileChangedSlot(self):
  19. print "event"
  20.  
  21. if __name__ == '__main__':
  22. app = QtGui.QApplication(sys.argv)
  23. watcher = FilesystemWatcher()
  24. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 

Can anybody confirm this?
Tips on how to handle this would've been great =)

Thanks