Tanalis has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I'm trying to debug a script that (can) spend a large amount of time in a foreach loop, processing and updating the records on a (very large) database.

However, I'm falling foul of a Perl "feature" that kills the script after it's been in a loop for 10 minutes or more, assuming (I presume) that it's stuck in an infinite loop.

The only indication of this that I get (apart from the script dying) is the message Alarm Clock. I haven't defined anything (yet) that could cause this, so I'm assuming it's a Perl thing.

Now, I'm about to write a handler that drops out of the loop every 599 seconds (ie, 1 second before the script is killed) and returns to it, essentially to allow the loop to carry on from where it left off each time.

Before I do that, though, I thought I'd ask and see if anyone knows of a way to override the 10 minute limit on loop structures? I don't know if it's a local thing or not - I can't find any reference to it at all in the Camel or Black Book, it's just very annoying to keep have happening.

Any advice or suggestions would be a great help.

Cheers
--Foxcub

Replies are listed 'Best First'.
Re: Script Timeouts
by nothingmuch (Priest) on Nov 08, 2002 at 08:40 UTC
    I don't think it's a perl thing - i've given perl loops that take days to chew. Is this a CGI script? that could be a more reasonable explanation, as a timeout is usually associated with requests. It's simply not logical that perl/Perl would enforce such a thing.

    A possible solution could be the to make a script which forks, one process printing an HTML page which redirects to a file, and the other writing the output data to the file, allowing the user to refresh when appropriate.

    Update: Disambiguated lexical sub-object relation by s/a/the/.

    -nuffin
    zz zZ Z Z #!perl
      It's not CGI, no - it's "straight" Perl.

      I'm running Perl 5.004.04 for sun4-solaris.

      --Foxcub

Re: Script Timeouts
by DamnDirtyApe (Curate) on Nov 08, 2002 at 09:05 UTC

    Between Google and the Perl Cookbook, I think you need to block the ALRM signal to prevent your program from timing out. According to the Cookbook, you ought to use the POSIX module's interface to the sigprocmask system call.


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: Script Timeouts
by robartes (Priest) on Nov 08, 2002 at 08:42 UTC
    Are you using Oracle on Solaris perchance? A quick tour of the web turned up the following in Google's Usenet archive groups.google.com.

    This might bite you if you have previously set an alarm and cleared it (but not, as the post points out).

    Then again, this thing is so specific (Oracle, Solaris, and you need to have set and cleared an alarm around the connect call), that it's probably not relevant to your problem.

    CU
    Robartes-

      I'm using Sybase on Solaris .. but it's definitely Perl, not Sybase, that's killing the process.

      I'm wondering if it's something that's been compiled in locally to prevent system resources getting eaten forever on the batch machines, and it's cascaded down onto the workstations too. (if that's the case there's probably nothing I can do about it .. *sigh*)

      --Foxcub

Re: Script Timeouts
by helgi (Hermit) on Nov 08, 2002 at 10:06 UTC
    Well, its definitely neither a Perl nor a Solaris thing. I too have run Perl loops for days on Solaris machines.

    You won't find any reference to it in the Camel nor the Black Book because the problem has nothing to do with Perl. Try writing a long loop in some other programming language. You will almost certainly get the same result.

    My best guess is that it's something your sysadmin set up to prevent resource hogging.

    Good luck finding out. Have you examined the process table for daemons with likely sounding names like alarm?

    --
    Regards,
    Helgi Briem
    helgi AT decode DOT is

      Yeah, that's what I figured.

      It's interesting, though, because it only affects Perl loops (it doesn't even affect function calls or system calls). I have a csh script that's been in a foreach loop for over 5 days at the minute ...

      There's nothing obvious on the process table, as far as I can see.

      Anyway, thanks for the help .. I'll give the sysadmin a call and see what he has to say for himself :)

      --Foxcub

Re: Script Timeouts
by Tanalis (Curate) on Nov 08, 2002 at 11:03 UTC
    Update: I've just found this from doing some Google searches on the problem .. apparently this is a bug in Perl on Solaris.

    Strange but true.

    I guess the handler that lets the loop restart after 599 seconds is the only option, then.

    Thanks for the help ..

    --Foxcub

Re: Script Timeouts
by petral (Curate) on Nov 08, 2002 at 22:48 UTC
    I had this problem once.    After I put this
    $SIG{HUP} = $SIG{ALRM} = 'IGNORE';
    in my code, it went away.   (Maybe also with  set -o nohup in ksh startup, although it's not there now.)

      p