CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
perl hangs

 



kp2a
New User

Mar 4, 2015, 3:06 AM

Post #1 of 4 (24193 views)
perl hangs Can't Post


need suggestions how to trouble shoot
moderate size program that hangs
in a tight loop

all of the modules that deal with external (network) devices are protected in a 5 second timeout

Code
    eval { 
local $SIG{ALRM} = sub {die "alarm\n" ; } ;
alarm $TIMEOUT ;
%$hashref = Mtik::get_by_key('/interface/wireless/print',$key);
$remaining = alarm 0 ;
};
if($@) {
return "timed out";
}


all the modules have been used for years in smaller programs
most of the modules depend upon the Mikrotik API module
use api::Mtik;


hangs when retrieving data from remote boxes over the network
(using API interface of remote box)

hangs in random modules but always at the same point in a download in the same module for a given configuration

a separate program - a simple script with just one module - works just fine at the same time as the hang !





525 lines
use 18 modules

[john@scan os]$ uname -a
Linux scan.broadband.vi 2.6.26.8-57.fc8 #1 SMP Thu Dec 18 19:19:45 EST 2008 i686 i686 i386 GNU/Linux

top
12662 john 20 0 18640 10m 2896 R 92.5 0.5 42:16.98 CheckOS.pl
92.5 % CPU
10m Mem: 2075156k total, 2015344k used, 59812k free, 68824k buffers
Swap: 2031608k total, 55700k used, 1975908k free, 1574380k cached

john@scan os]$ perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi



FishMonger
Veteran / Moderator

Mar 4, 2015, 6:35 AM

Post #2 of 4 (24185 views)
Re: [kp2a] perl hangs [In reply to] Can't Post


Quote
hangs in random modules but always at the same point in a download in the same module for a given configuration

That statement contradicts itself. You say it hangs in random modules, but then say that it's always the same module. Which is it?

Have you narrowed down the exact statement it's executing when it hangs?

Since you posted your eval block, are you saying that it hangs when executing this statement?

Code
%$hashref = Mtik::get_by_key('/interface/wireless/print',$key);


What debugging steps have you already taken?

Have you tried stepping through the script with the debugger or use Devel::Trace to see how it progresses and where it hangs?
http://search.cpan.org/~mjd/Devel-Trace-0.12/Trace.pm

I see a disconnect between these 2 statements.

Code
use api::Mtik; 

%$hashref = Mtik::get_by_key('/interface/wireless/print',$key);

Based on your use statement, the sub call should be:

Code
%$hashref = api::Mtik::get_by_key('/interface/wireless/print',$key);



kp2a
New User

Mar 4, 2015, 7:57 AM

Post #3 of 4 (24179 views)
Re: [FishMonger] perl hangs [In reply to] Can't Post

by golly, you did it! many thanks!

these modules have been used for years without the prefix
first test with prefix runs!
will test further

in the past, however the modules, were used in small numbers
in varius small scripts for different purposes
current project was to cram all 18 into one script
like a swiss army knife

so now I, (maybe we), will learn something new about perl?
what does leaving off the prefix do to perl?
-w and use strict
no complaints!



Code
ls -lt 
. . .
-rwxr-xr-x 1 root root 2457 2013-01-25 19:02 setmac.pm
-rwxr-xr-x 1 root root 304 2013-01-22 21:23 queue.pm
-rwxr-xr-x 1 root root 1075 2013-01-22 21:23 createcommand.pm
[john@scan api]$

hang occurs in a different module depending on the exact configuration of the run - debug options, identity of the remote box (Mikrotic), etc.

for for a given configuration, I hangs in the same module and at the same place in the, say, reply from the remote box.

and yes, all modules that hang have the same timeout code


FishMonger
Veteran / Moderator

Mar 4, 2015, 8:34 AM

Post #4 of 4 (24174 views)
Re: [kp2a] perl hangs [In reply to] Can't Post

What you call the "prefix" is the directory path. Your use statement is saying that the Mtik.pm module is in the api directory which is in one of your @INC paths or in some cases it could be in the same dir as the script you're running. If the module can't be found in the specified path, then the script will fail with a compilation error.

BTW,
You should use the warnings pragma instead of the -w switch. The pragma is lexically scoped but the -w switch is globally scoped and because of that, you could get warnings propagating from modules which weren't written properly to handle warnings.

You should also not use all lowercase names for your modules (and their path). By convention all lowercase names are reserved for pragmas (such as strict and warnings).

In addition to the debugging suggestions I made, you should also profile your script(s) to see where they are spending their time. The best way to do that would be to use the Devel::NYTProf module.
http://search.cpan.org/~timb/Devel-NYTProf-5.07/lib/Devel/NYTProf.pm

For low level debugging, run the script under strace.
http://linux.die.net/man/1/strace

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives