Dangerous update command
- From: Mats <matsben@xxxxxxxxx>
- Date: Wed, 28 Nov 2007 05:15:58 -0800 (PST)
Dear all,
In my Coccinella app I have code that transfer files back and forth
and I have until now been using 'update' or 'update idletasks' to keep
the GUI responsive, but was getting errors that the recursion limit
was reached. This was nothing but the "Update considered harmful"
http://wiki.tcl.tk/1255 problem, and I now understand how stupid it
is. I just want to have some feedback how to use the trick 'after idle
[list after 0 [list ...]]' in a situation with fileevents.
My code looked roughly like:
fileevent $sock readable [list Readable $sock]
proc Readable {sock} {
if {[catch {eof $sock} iseof] || $iseof} {
...
} else {
set data [read $sock]
# Write to file etc.
...
update_progress_window $data
# WRONG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if {[string equal $::tcl_platform(platform) "windows"]} {
update
} else {
update idletasks
}
}
Rewritten it looks like:
proc Readable {sock} {
fileevent $sock readable {}
if {[catch {eof $sock} iseof] || $iseof} {
...
} else {
set data [read $sock]
# Write to file etc.
...
update_progress_window $data
after idle [list after 0 [list SetReadable $sock]]
}
}
proc SetReadable {sock} {
# We could have been closed since this event comes async.
if {[lsearch [file channels] $sock] >= 0} {
fileevent $sock readable [list Readable $sock]
}
}
In short, I switch off fileevent for each callback, and then
reschedule it to be switched on again when the UI events finished.
Some testing shows that this makes a fast and responsive UI, but is
this the right way? Any pitfalls? Then similar code for 'fileevent
writable'.
Personally I'd like to see a updateEventObjCmd from http://wiki.tcl.tk/1252
/Mats
.
- Follow-Ups:
- Re: Dangerous update command
- From: Donald Arseneau
- Re: Dangerous update command
- Prev by Date: selecting nvarchar with Oratcl?
- Next by Date: Re: selecting nvarchar with Oratcl?
- Previous by thread: selecting nvarchar with Oratcl?
- Next by thread: Re: Dangerous update command
- Index(es):
Relevant Pages
|