Skip Menu |

This queue is for tickets about the Expect CPAN distribution.

Report information
The Basics
Id: 21221
Status: rejected
Priority: 0/
Queue: Expect

People
Owner: Nobody in particular
Requestors: james.petitt [...] viasat.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.20
Fixed in: (no value)



Subject: thread friendly
Spawning a new expect object in a thread does not work. The object spawns without errors, but then no expect data is recieved from the spawned session. I found this error using perl v5.8.8 built for i686-linux-thread-multi, Expect v1.20, and IO::Tty v1.07. The attached script should return a ping response before the main thread dies, however I receive "A thread exited while 2 threads were running."
Subject: thr_expect.pl
use Expect; use threads; threads->new( \&thr ); for (my $i=0;$i<7;$i++) { print "Parrent: waiting\n"; sleep 2 } sub thr { my $exp = Expect->spawn("ping -c 4 172.18.40.40") || die "couldn't spawn"; while (1) { print $exp->expect(1, "icmp"); } }
Sorry, it is not possible to spawn() in a thread, because this does a fork(). From perlthrtut: "Thinking of mixing fork() and threads? Please lie down and wait until the feeling passes." It is possible to spawn() in the main thread and then work with the Expect object in threads though... -- RGiersig@cpan.org