I'm running this on perl 5.12.4 on Ubuntu 11.10. Please help me save the little hair
Make sure your Ubuntu version of Perl is compiled to use threads.... I seem to recall Ubuntu may install a non-threaded Perl as default.
#!/usr/bin/perl use warnings; use strict; use threads; my $thr; for(1..10){ $thr = threads->new( \&sub1 )->detach; # Spawn the thread } while(1){ my $thread_count = threads->list(); print "\n\n\n\t\t",'num threads ', $thread_count, "\n\n\n"; print "Hit control c to exit \n\n\n\n"; sleep 1; } exit; sub sub1 { use Net::SSH2; # assuming a user named 'z' for demonstration # connecting to localhost, so you need your sshd running # see maillist archives at # http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users # for deeper discussions my $self = threads->tid(); my $ssh2 = Net::SSH2->new(); $ssh2->connect('localhost') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('z','ztester') or die "Unable to login $@ \n"; #shell use my $chan = $ssh2->channel(); $chan->blocking(0); $chan->shell(); print $chan "ls -la\n"; print "thread $self : $_" while <$chan>; print $chan "who\n"; print "thread $self : $_" while <$chan>; print $chan "date\n"; print "thread $self : $_" while <$chan>; $chan->close; }
In reply to Re: Net::SSH2 not thread safe?
by zentara
in thread Net::SSH2 not thread safe?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |