Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

My code randomly stops working

by newbie1991 (Acolyte)
on Mar 27, 2013 at 14:33 UTC ( #1025726=perlquestion: print w/replies, xml ) Need Help??
newbie1991 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perlmonks, I'm having a strange problem when running my programs. The code is correct and it is giving me all the right outputs. I've been using the same program on a set of around 700 files, (in sets of 100 each because my system is prone to hanging) and the program just eventually stops working. The print statements give output in the Terminal but do not create the requires files. I haven't made any changes to the code, and it has, for some reason, slowly stopped working over the course of the day. P.S. : My work computer is slow, but clean and no viruses. Code is correct with no errors. I realise this isn't a code-related matter as such but this is not happening with other programs so I was wondering if others have experienced this. I would have asked in the Chatterbox but I don't think people were available there. Thanks for your help. :)

Replies are listed 'Best First'.
Re: My code randomly stops working
by McA (Priest) on Mar 27, 2013 at 14:38 UTC


    where does the script run? Win, Mac, Unix?

    Can you look at resource consumption while running? It sounds like your script runs out of resources. E.g. files not closed, variables not freed.

    That's the only guess I have without any further information assuming you're right having no errors in your script.


      Script is running in Unix. I've closed files but I'll go over it again, thank you :)

        Show us your code, we show you the errors... ;-)


Re: My code randomly stops working
by marto (Archbishop) on Mar 27, 2013 at 14:39 UTC

    Without showing the code in question people can only suggest that you debug the program, logging events in an attempt to diagnose what's going on. What error checking does your code have? Are you running out of memory? Is file locking a problem? Are you hitting an OS defined limit? Debugging and Optimization, Basic debugging checklist and so on. Don't wait to ask a quesiton in the chatterbox, just ask. People did reply to your "Hello?" question.

      Hi, yes, I noticed the replies just after I'd posted the question. Anyway, thank you, and I will go over my code once again with the checklist in mind. :)
Re: My code randomly stops working
by blue_cowdawg (Monsignor) on Mar 27, 2013 at 15:02 UTC
        I'm having a strange problem when running my programs. The code is correct and it is giving me all the right outputs.

    You haven't posted any code so we have no way to comment on that.

    If a piece of code just stops working something has to have changed. This could be any of the following:

    • Environment.
    • Resources
    • Input
    Computers are fairly deterministic in nature so "random" doesn't really play into this space well. Something, somewhere has to change for your code to just stop working.

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      One anecdote to relate: Where I work there is a piece of Perl code that processes thousands of emails. One of the early "bugs" discovered in this code was that it grew RSS wise and since there were several copies of this code running constantly this could become a problem. To solve the issue the developer added introspective code to determine the scripts RSS size and if it went over a certain amount it spawns and dies.

      Given that you stated that the issue you are experiencing happens after the code has been running for a while maybe you could do something similar?

      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

        The better: As soon as the process uses more than a defined amount of memory it should invoke a machine reboot...


        P.S.: Sorry, couldn't resist ;-)

Re: My code randomly stops working
by ww (Archbishop) on Mar 27, 2013 at 20:08 UTC

    You say " my system is prone to hanging...."

    Please tell us (along with the other requested info) how you distinguish between "hanging" (system problem) and "randomly stops working" (code problem as id'ed in your title)

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: My code randomly stops working
by sundialsvc4 (Abbot) on Mar 27, 2013 at 14:58 UTC

    Here are a couple of CPAN modules that you should look at just for their descriptions:   Test::Memory::Cycle, and Scalar::Util, the latter specifically in reference to weaken.

    It certainly appears to us that the root cause of the problem is that the program is exhausting memory.   Most likely, the system begins to “thrash” as a result of this issue, and that’s physically-speaking what actually brings it to its knees.   One subtle problem that I am thinking of, hence the first paragraph, is that of circular memory-references which prevent storage from being cleaned up successfully after it has been released.   But, another possible problem is that storage structures such as hashes aren’t emptied before the start of the next run ... e.g. by use of undef.

    One fairly easy-to-do structural rehab that I have sometimes tried, with programs that need to process a lot of files in sequence, is to put the file-scanning loop as the main program, and have it call a subroutine for each file.   All of the data structures needed are made local to that one subroutine, so that everything goes away “in one swell foop” when the subroutine ends ... provided that there are no circular storage-references in play.   (If any globals are needed, the subroutine in its first few statements explicitly undefs each and every one.)   This is a fairly simple re-factoring to do with most existing, hairy programs, because it doesn’t attempt to restructure the main-line logic ... it merely puts it into a box.

    Amazing!   A down-vote, not five seconds after this posting was made!   Is anyone out there, like, running a “bot” that will do this?   Just askin’ ...   I find it quite entertaining, really.   Pathetic, but laughable ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025726]
Approved by marto
[vedagiri89]: that is what i can't getting solution
[vedagiri89]: recently purchased centos server and doing migration of app
[choroba]: did you copy any dependencies?
[choroba]: all XS code needs to be recompiled
[vedagiri89]: install perl5.16 in the new server and try to run appache
[hippo]: Which version of CentOS?
[vedagiri89]: how to fix: Attempt to reload aborted
[hippo]: Ah, presumably 7 then.
[vedagiri89]: CentOS Linux release 7.0.1406 (Core)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-06-19 11:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (113 votes). Check out past polls.