RE: [Ssh-sftp-perl-users] are net::ssh::perl and net::sftp considered thread safe?
Brought to you by:
dbrobins
From: Yishay W. <yis...@ho...> - 2005-06-22 06:58:46
|
These are the problems I encounter on win2k ActivePerl 5.8.7 using Net-SSH-Perl [1.23_01] when using fork(): For this code: =============================== use Net::SSH::W32Perl; use strict; my $user = 'user'; my $password = 'password'; my $fileName = "~$user/dummy_file2"; my $ssh = createSsh(); my $i = 1; while (1) { print "starting...\n"; runInLoop(); print "sleeping 10\n"; sleep 10; print "finished iteration ".$i++."\n"; } sub isRunning { my $ssh = shift; my ($out, $err, $exit) = $ssh->cmd("ls $fileName"); # print "out: $out\nerr: $err\nexit: $exit\n"; return !$err && $out; } sub createSsh { my $time = time(); my $ssh = Net::SSH::W32Perl->new('host'); $ssh->login($user, $password); print "ssh created after ", time() - $time, "\n"; return $ssh; } sub runInLoop { my $time = time(); my ($out, $err, $exit) = $ssh->cmd("rm $fileName"); if (isRunning($ssh) ) { print "error removing $fileName\n"; return; } my $ssh2 = createSsh(); unless (my $pid = fork() ) { startAction($ssh2); while (1) {} } else { print "out of command after ", time - $time, "\n"; my $isRunning = isRunning($ssh); sleep 5; kill (9, $pid); while (time() - $time < 60) { last if ($isRunning = isRunning($ssh) ); } my $howlong = time() - $time; if ($isRunning) { print "start was successful after $howlong\n"; } else { print "failed after $howlong\n"; } } } sub startAction { my $ssh2 = shift; my $cmd = "sleep 20; touch $fileName; sleep 60; "; print "executing cmd: $cmd\n"; my ($out, $err, $exit) = $ssh2->cmd($cmd); } ======================== I get: ======================== C:\yishay>perl test_fork.pl ssh created after 2 starting... ssh created after 0 out of command after 1 executing cmd: sleep 20; touch ~yishayw/dummy_file2; sleep 60; Bad packet length 1927540882 at C:/Perl/site/lib/Net/SSH/Perl/Packet.pm line 171 Bad packet length 1523729943 at C:/Perl/site/lib/Net/SSH/Perl/Packet.pm line 171 C:\yishay>perl test_fork.pl ssh created after 0 starting... ssh created after 0 out of command after 1 executing cmd: sleep 20; touch ~yishayw/dummy_file2; sleep 60; Corrupted MAC on input at C:/Perl/site/lib/Net/SSH/Perl/Packet.pm line 189 Corrupted MAC on input at C:/Perl/site/lib/Net/SSH/Perl/Packet.pm line 189 ===================================== similar problems happen when using threads instead of fork(). Note that the same code appears to work fine on WinXP for fork(), but not using threads. I also tried using alarm signals on both platforms and did not get the desired results - alarm just didn't seem to go off. So my conclusion is: for non-blocking operations on windows using Net::SSH::Perl you can use fork() on XP but there's no solution for win2K. If anyone cares to challenge that assumption she'd be most welcome. Thanks, Yishay >From: "Yishay Weiss" <yis...@ho...> >To: ssh...@li... >Subject: [Ssh-sftp-perl-users] are net::ssh::perl and net::sftp considered >thread safe? >Date: Sun, 19 Jun 2005 09:22:38 +0000 > >Hi, > >In order to use net::ssh::perl and net::sftp in a non blocking fashion I'm >considering using them with threads. I first would like to know if it's >considered safe. I'm using perl 5.8 on windows. > >I already tried using fork() for the same purpose but encountered some >problems on win2k. I would sometimes get an error message. I can't >currently reconstruct the problem I had with fork(). I might give more >precise info in a separate post. I was only wondering if anyone's tried >using threads for this purpose or if a different non-fork() solution >exists. Using expect.pm seems like overkill for me, anyway it appears to >just be a variation of the fork() solution if I'm correct. > >Thanks, >Yishay > >_________________________________________________________________ >Dont just search. Find. Check out the new MSN Search! >http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >_______________________________________________ >Ssh-sftp-perl-users mailing list >Ssh...@li... >https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users _________________________________________________________________ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 |