[pygtk] A Timer and refreshing TextView
njs at pobox.com
Mon Dec 3 14:52:45 WST 2007
On Sun, Dec 02, 2007 at 09:34:40PM -0800, Aravind Vijayakumar wrote:
> Since you are opening the file afresh each time in refreshLog, won't
> you be reading the first line each time?
The .read() method in Python reads the whole file, not just the first
> You probably want a
> persistent open stream from which you can keep reading. Also, have a
> look at gobject.io_add_watch, it is probably simpler than threading
> for your needs.
Unix does not support watching for io for on-disk files (at least not
in the normal ways); io_add_watch only works for things like pipes and
However, Mark: I don't know the answer to your problem, but the use of
threading does look very questionable here. GTK+ is not designed to
be used in a heavily-multithreaded environment; it has some minimal
hooks, but basically assumes that you will do all of your interaction
with GTK+ from a single thread.
> > timer = threading.Timer(10, self.refreshLog)
Instead of this, try
gobject.timeout_add(10 * 1000, self.refreshLog)
to request that the GTK+ main-loop call your function every 10 seconds
(= 10,000 milliseconds). It will keep calling your function until it
returns False rather than True (and note that if you don't return
anything, then Python automatically returns None, which is considered
false). So also add a 'return True' to the end of your refreshLog
function. Don't know if this will help, but it might.
Damn the Solar System. Bad light; planets too distant; pestered with
comets; feeble contrivance; could make a better one myself.
-- Lord Jeffrey
More information about the pygtk