On 21/01/2013 08:49, Lars Beiderbecke wrote:
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?
No answer on top of my mind, but I'd run all the commands (cp, vi, jo, cat)
under strace and see all the related syscalls. Won't be surprised if the
*notify system has some hooks related to common syscalls.
--
Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666318 Fax: +390302659932
E-mail: [email protected]
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt