Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

keep running out of memory, help a newbie!

by kixsnap (Novice)
on Feb 14, 2017 at 00:11 UTC ( [id://1181941]=perlquestion: print w/replies, xml ) Need Help??

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

Sorry if i'm not doing this right, still rather new to perl and new to this website. This keeps happening to me and i'm not sure why, i've written scripts that will check to see if a webpage is accessible and if it is I use threads to make a new thread in the program to notify me via twitter (just testing, the sub will do other things) I use a while(1) loop to continually check the webpage via WWW::Mechanize, and if its live, it'll create the threads, what happened a couple times if the program runs for awhile, is that when it goes to create the thread, i get an Out Of Memory error and i'm not sure how to avoid this.
--Code-- use WWW::Mechanize; use HTTP::Cookies; use threads; $|=1; my $cookie_jar = HTTP::Cookies->new; $mech = WWW::Mechanize->new( agent => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:21.0)', cookie_jar => $cookie_jar, timeout => "15", autocheck => 0); $url = 'http://www.fwrd.com/product-military-boots/YEF3-MZ2/'; # page will default to error page if not around... $delay = 15; check(); sub check { print "[x] starting...\n"; while(1) { $resp = $mech->get($url); if((!$resp->is_success) || ($resp->request->uri =~ m/error/i)) { print "."; } else { for $sz (1..5) { $thread = threads->new( sub { notify_plz($sz) }); my $tid = $thread->tid; push (@Threads, $thread); $thread->detach(); } # we saw the page , exit exit; # end what we do if its found } sleep $delay; } }
not sure what i'm doing wrong,any help is appreciated, didnt post notify_plz cuz the script doesnt even seem to get to that point.

Replies are listed 'Best First'.
Re: keep running out of memory, help a newbie! ( $mech->back , threads stack_size)
by beech (Parson) on Feb 14, 2017 at 01:37 UTC
Re: keep running out of memory, help a newbie!
by LanX (Saint) on Feb 14, 2017 at 00:29 UTC
    Hi kixsnap, welcome to the monastery!

    > not sure what i'm doing wrong

    It's pretty unreadable because of erratic indentation.

    Could you fix that, please?

    Probably your endless loop is causing problems.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      not sure how else to do the loop, wouldnt a for(;;) be the same thing and end up the same way? or am i missing something?
        ... use constant LEVEL_1_LOOP_MAXIMUM => 1400; # This code keeps the +program from looping forever. my $level_1_loop_counter; FOLLOW_LEVEL_1_LINK: for ( $level_1_loop_counter = 1 ; $level_1_loop_counter <= LEVEL_1_LOOP_MAXIMUM ; $level_1_loop_counter++ ) { #------------------------------------------ print $fh_log "Level_1_loop_counter: $level_1_loop_counter\n"; if ( $level_1_loop_counter > LEVEL_1_LOOP_MAXIMUM ) { die "Runaway program.\n"; } ...

        Notice the belt and suspenders approach.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1181941]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-23 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found