Create a gist now

Instantly share code, notes, and snippets.

@dgsb /runnee.tcl
Last active Aug 29, 2015

What would you like to do?
Expect core dump
# \
exec tclsh "$0" "$@"
set nb_iter 1000
set sleep 500
for {set i 0} {$i < $nb_iter} {incr i} {
after $sleep
puts $i
# \
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