Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Expect core dump

View runnee.tcl
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh
# \
exec tclsh "$0" "$@"
 
set nb_iter 1000
set sleep 500
 
for {set i 0} {$i < $nb_iter} {incr i} {
after $sleep
puts $i
}
 
View runnee.tcl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/bin/sh
# \
exec tclsh "$0" "$@"
 
package require Expect
 
set nb_subproc 20
set sid_list [list]
set ::completed {}
 
for {set i 0} {$i < $nb_subproc} {incr i} {
spawn [file normalize [file join [file dirname $::argv0] runnee.tcl]]
lappend sid_list $spawn_id
expect_background {
-i $spawn_id eof [list set ::completed $spawn_id]
}
}
 
set aid [after 1200000 {set ::completed timeout}]
while {[llength $sid_list] > 0} {
vwait ::completed
if {"timeout" eq $::completed} {
error timeout
}
set idx [lsearch $sid_list $::completed]
if {-1 == $idx} {
error "spawn_id $spwan_id not found in \"$sid_list\""
}
set sid_list [concat [lrange $sid_list 0 $idx-1] [lrange $sid_list $idx+1 end]]
}
 
exit 0

afaik, there is no guarantee that vwait returns for every set ::completed. Should be re-written lappend ::completed $spawn_id and wrap the removal in foreach sid $::completed {...} ; set ::completed {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.