Re: sleep in tcl
- From: Donald Arseneau <asnd@xxxxxxxxx>
- Date: Wed, 28 Nov 2007 11:52:42 -0800 (PST)
yusuke wrote:
You can't rewrite this like the following.
# sample4
first_proc
after 2000 second_proc
after 2000 third_proc
As Allan writes, you should separate each section of continuous
execution into a separate proc, and have each proc schedule the
following proc to execute. If you have a lot of local variables for
your in-linwed proc, then you should probably make a namespace for
your sequence of small procs.
set ::stone 0
after 2000 {second_proc; set ::stone 1}
if {$::stone == 0} {vwait ::stone}
set ::stone 0
after 2000 {third_proc; set ::stone 1}
if {$::stone == 0} {vwait ::stone}
Again, don't use one continuous flow-through proc with vwait.
If you want to set a global variable, it would be useful to use a sort
of "semaphore" to prevent multiple proc streams from executing in
parallel.
Let's say you want to cancel any current processing sequence when a
new request comes in:
set ::procID {}
proc proc1 {args} {
global procID ;# or use a namespace var
after cancel $procID
blah blah
set procID [after 2000 {proc2 arg yew mints}]
}
proc proc2 {a y m} {
global procID
after cancel $procID
foo bar
set procID [after 4000 [list proc3 $a $y $e]]
}
proc proc3 {args} {
global procID
after cancel $procID
set procID {}
finalize
}
Alternatively, let's say tou want to reject new requests when a
processing stream is in progress. We will assume that a request that
hasn't completed in 10 seconds has failed, so a failure will not lock
things permanently.
set procTime 0
proc proc1 {args} {
global procTime ;# or a namespace variable
set now [clock seconds]
if { $procTime > $now - 10 } { return }
set procTime $now
...
after 2000 {proc 2 xx yy zz}
}
proc proc1 {args} {
....
after 4000 {proc 3 xx yy zz}
}
proc proc3 {args} {
...
set ::procTime 0
}
(Hope there aren't too many typos.)
Donald Arseneau asnd@xxxxxxxxx
.
- Follow-Ups:
- Re: sleep in tcl
- From: yusuke
- Re: sleep in tcl
- References:
- sleep in tcl
- From: yusuke
- Re: sleep in tcl
- From: Donald Arseneau
- Re: sleep in tcl
- From: yusuke
- sleep in tcl
- Prev by Date: Re: Dangerous update command
- Next by Date: Re: Plotchart ideas (was: Can BLT be replaced by Tcl packages ?)
- Previous by thread: Re: sleep in tcl
- Next by thread: Re: sleep in tcl
- Index(es):
Relevant Pages
|