I've been 'dabbling' with trying to write a threaded perl script. I thought I would try with something simple, just to get the ball rolling, or what I thought would be simple, please see the code below.
#!/usr/bin/perl use Net::SNMP; use threads; use Config; $Config{usethreads} or die "Recompile Perl with threads to run this p +rogram."; threads->new(\&polldevice,"192.168.1.50", "public"); threads->new(\&polldevice,"192.168.1.1", "public"); sub polldevice { my ($host, $community) = @_; ($session,$error) = Net::SNMP->session(Hostname => $host, Community => $community); die "session error: $error" unless ($session); $result = $session->get_request("1.3.6.1.2.1.1.2.0", "1.3.6.1.2.1.2.1. +0", "1.3.6.1.2.1.1.3.0"); die "request error: ".$session->error unless (defined $result); $session->close; print "Testing ".$host."\n"; sleep 10; print "Number of interfaces: ".$result->{"1.3.6.1.2.1.2.1.0"}."\n"; print "uptime: ".$result->{"1.3.6.1.2.1.1.3.0"}."\n"; print "sysOID: ".$result->{"1.3.6.1.2.1.1.2.0"}."\n"; }
The hope was that both devices would be polled at the same time, I was using the 'sleep 10' to try and proove this. The Code works fine when I pass in the polling details 1 by 1. When I run it all I get is,
A thread exited while 3 threads were running.
And nothing else gets printed to the window. I've even tried doing it in a 'use Threads' style, but keep seeming to get the same problem.
I'm using 5.8.8 on SUSE Linux 10.1 RC1.
I would be extremely grateful for any guidance
Thanks
Dave
In reply to Just can't get threads to work by stellagoddc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |