I have a tcl proc called run_expect that I use to run basic tcl expect flow: spawn <device>
, send <cmd>
, expect <string>
. Now I need to run this code from 2 threads running in parallel, I did the following attemps:
- when I tried to write the multi-threaded proc which simply calls
run_expect
I got the error of unknown commandrun_expect
from the thread's context/scope. - I tried to take the implementation of the
run_expect
proc and put it in the thread itself, but then I encountered another issue that the thread doesn't seem to see expect library as the other procs and complains on:"invalid command name "spawn"
. - I tried then to do
package require Expect
from the thread itself, but gotSegmentation fault: 11
error. - Tried to update the
::audio_path
variable of the thread to be same as main context but also didn't help making the package require work (::thread::send -async [lindex $tids 0] [list set ::auto_path $::auto_path]
)
Is there anyway to call any already existing proc from a thread? if not, is moving the code into the thread is the write solution? and how can I get the thread to know the packages / commands loaded?
expect
is not thread safe. You can't have multiple expect sessions in different threads. – Shawn