puts to stdout not happening if expect loaded in 2 threads

55 views Asked by At

I am using following version of Active Tcl on windows 10

C:\thread>tclsh
% puts $tcl_version
8.6
% package require Thread
2.6.6
% package require Expect
5.43.2

I am trying to use Expect in 2 threads. But puts to stdout not happening when package require called in both threads.

package require Thread
#package require Expect

thread::create {
package require Expect
exp_log_user 1
puts "hello"
}

thread::create {
package require Expect
exp_log_user 1
puts "hello2"
}

after 2000

output:

C:\thread>tclsh samp2.tcl
hello

C:\thread>

Can someone please help guide on this.

Thanks in advance. uv.

1

There are 1 answers

1
Colin Macleod On

I'm pretty sure Expect is not thread-safe, so there's no way this is going to work, sorry.

You could consider using coroutines instead of threads to manage multiple sessions in parallel. Expect can be integrated cleanly with coroutines, I give an example of one approach to this at https://wiki.tcl-lang.org/page/coroutine%2Denabled+event+handling - search for co_expect on that page.