PDA

View Full Version : QFilesystemWatcher fileChanged events



rhblind
17th August 2011, 11:19
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.


# -*- coding: utf-8 -*-
#!/usr/bin/env python

import sys
from PyQt4 import QtCore
from PyQt4 import QtGui

class FilesystemWatcher(QtCore.QFileSystemWatcher):
def __init__(self, parent=None):
QtCore.QFileSystemWatcher.__init__(self, parent)

path = "/home/rolf/Desktop/Driver2.dat"
self.addPath(path)

self.connect(self, QtCore.SIGNAL("fileChanged(const QString&)"), self.fileChangedSlot)


def fileChangedSlot(self):
print "event"

if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
watcher = FilesystemWatcher()
sys.exit(app.exec_())

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

Thanks