Skip to content

Instantly share code, notes, and snippets.

@dgsb
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgsb/9209160 to your computer and use it in GitHub Desktop.
Save dgsb/9209160 to your computer and use it in GitHub Desktop.
Expect core dump
#!/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
}
#!/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
@heinrichmartin
Copy link

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