[PyQt] QFileSystemWatcher triggering too many signals
Lars Beiderbecke
lars.beiderbecke at gmail.com
Mon Jan 21 07:49:29 GMT 2013
Hello,
I'm trying to watch a file for changes using QFileSystemWatcher:
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent,args=None):
QtGui.QMainWindow.__init__(self)
self.count = 0
self.watcher = QtCore.QFileSystemWatcher();
self.watcher.addPath("myfile");
self.connect(self.watcher, QtCore.SIGNAL("fileChanged(const
QString&)"), self.check)
def check(self, file = "*"):
self.count += 1
print "Modified:", str(file), " #", self.count
This works, more or less, as for every
$ touch myfile
I get exactly one invocation of check(). If the changes are larger,
however, I get an excessive amount of invocations. Some examples:
$ dd if=/dev/urandom of=sample bs=1k count=100
$ cp sample myfile
-> 4 invocations
$ vi myfile # replacing first char, then :wq
-> 21 invocations
$ joe myfile # ditto
-> 11 invocations
$ touch myfile
-> 1 invocations
$ cat sample > watched
-> 3 invocations
$ cat sample sample > watched
-> 6 invocations
Now I realize that editors may do weird things to files, but cp and
cat? Is this behavior considered normal?
System info: Ubuntu Precise, Linux kernel 3.2.0-36 x86_64, Python
2.7.3, PyQt 4.9.1 (?)
Regards
Lars
More information about the PyQt
mailing list