Tkinter app 'freezes' when I use after_idle

Doug Hellmann doughellmann at home.com
Fri Oct 29 07:29:03 EDT 1999


Andrew Markebo wrote:
> 
> I am working on an Tkinter application that is supposed to fetch data
> from the internet (wow!) (a deja-client).
> 
> So I have done myself a small module that by request (for example from
> the Tkinter.after_idle) does select on a list of sockets, and if there
> exists any data, fetches it, and if all data is received, calls a
> callback.
> 
> It works.. except for that the application window freezes, except for
> the parts that I update with info about what happens.. It seems as
> thought tkinter doesn't take its time to update..
> 
> I have tried to do a after(100, after_idle, params) so it should let
> tkinter do its stuff (or have I got something wrong here)?

Tk will not update the display while you are doing work in your idle
handler unless you call update() or update_idletasks().  It sounds like
you are doing that for some widgets, as you see some changes on the
display.  But if your idle handler blocks while reading data from the
network, it might take a while to come back.  Keep in mind that as long
as the program is running your callback code, the display will not be
updated.  

You could use a file handler to let Tk watch the socket for you (instead
of doing your own select).  You would then get a callback when there is
data for you to read from the socket.  I've had success with this scheme
watching the read end of a pipe.  As a little bit of data is available,
I read it into a buffer.  When the pipe is empty (read 0 bytes in the
event handler), I know I have all of the data and I start doing the real
processing.  Of course, if you can process part of the data at a time
that would be even more efficient.

Doug




More information about the Python-list mailing list