in reply to Re^4: MozRepl cleanup problem
in thread MozRepl cleanup problem

Sadly, I can't ignore the warnings as when they appear it means the script has abruptly ended itself (before the real end of the cycle).

No. Global destruction happens at the end of your program, not somewhere in the middle. If you fork(), you maybe get that, so don't do that then.

If you post a complete, self-contained example that reproduces the problem but is not longer than 20 lines, that would help me to help you better. I could then try to reproduce what you're seeing and maybe find what causes it easier.

Replies are listed 'Best First'.
Re^6: MozRepl cleanup problem
by giantpanda (Initiate) on Nov 01, 2010 at 13:26 UTC

    I managed to make a reduced version of that part of my script, sadly I couldn't manage to reduce it under 50 lines.
    Would that be fine for you?

    UPDATE: Here is the code and some nicknames to test it:

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; use WWW::Mechanize; use Date::Manip; use DateTime; open TXT, "<", "nickname.log"; while(! eof (TXT)){ my $nick = <TXT>; chomp $nick; open MATCH, "+<", "match.log"; my $j = 0; for $j(0..3){ my ($date) = DateTime->now; my ($k) = 0; while($k < $j){ $date = $date->subtract( days => 7); $k++; } $date = $date->ymd; my $url = "http://www.quakelive.com/#profile/matches/$nick/$da +te"; my ($firemech) = WWW::Mechanize::Firefox->new(); $firemech->get($url); die "Cannot connect to $url\n" if !$firemech->success(); my ($retries) = 10; while ($retries-- and ! $firemech->is_visible( xpath => '/ +/*[@class="areaMapC"]' )) { sleep 1; } die "Timeout" unless $retries; my ($content) = $firemech->content(); while(($content =~ /class="areaMapC" id="([^<]+)_([^<]+)_([^<] ++)">/gsi)){ my ($game) = $1; my ($longid) = $2; my ($shortid) = $3; my ($matchid) = "$longid/$game/$shortid\n"; print MATCH $matchid; } undef $firemech; undef $content; $j++; } close MATCH; } close TXT;

    Nicknames:

    peavey trajan komap bluedawg donpidon x9rcist dom_prova_____ newton burn tyryl st1mz tomo32 zky hisarrzulu _luk__47_ sendhu joopsta sand5pid3r trickle mikenoid beg1nner fladder72 4bsan1ty daitarn z0id0uf amoreno stuntt askkk flyttadig arcsign glavic acid_predator new_0 jala1 crucci niko95 deputydawg optixx ennesit martianbuddy b4r r1dah gathion function9 chup4 poocamshot shnipzr heppo b4byb34r the_hulk

      It seems that you were fighting two problems. One I can't easily fix - it seems that MozRepl::Client does not like getting instantiated twice. You can fix that by only ever using one instance of WWW::Mechanize::Firefox, outside of your loop. The second problem is that Firefox does not fire the proper events when moving to a new URL, if the new URL only differs in the anchor part from the old URL. I've changed your program to simply do two ->get() calls, one to about:blank to flush the current page, and then one again to the new real URL.

      I've also removed the use Date::Manip statement, as it wasn't used at all. There was $j used as a counter but incremented in two places. I've removed the explicit increment. The HTML extraction seemed easier when done using the ->selector() method of WWW::Mechanize::Firefox.

      Here is the program that works for me:

      #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; use WWW::Mechanize; use DateTime; my ($firemech) = WWW::Mechanize::Firefox->new(); my $count; while($count++ < 2){ my $nick = <DATA>; chomp $nick; #my $j = 0; for my $j(0..3){ my ($date) = DateTime->now; my ($k) = 0; while($k < $j){ $date = $date->subtract( days => 7); $k++; } $date = $date->ymd; $firemech->get('about:blank'); my $url = "http://www.quakelive.com/#profile/matches/$nick/$da +te"; $firemech->get($url); die "Cannot connect to $url\n" if !$firemech->success(); my ($retries) = 10; while ($retries-- and ! $firemech->is_visible( xpath => '//*[@ +class="areaMapC"]', all => 1 )) { sleep 1; } die "Timeout" unless $retries; my ($content) = $firemech->content(); while(($content =~ /class="areaMapC" id="([^<]+)_([^<]+)_([^<] ++)">/gsi)){ my ($game) = $1; my ($longid) = $2; my ($shortid) = $3; my ($matchid) = "$longid/$game/$shortid\n"; print $matchid; }; my @areaMapC = $firemech->selector('.areaMapC'); print $_->{id},"\n" for @areaMapC; #$j++; } } undef $firemech; __DATA__ peavey trajan komap bluedawg donpidon x9rcist dom_prova_____ newton burn tyryl st1mz tomo32 zky hisarrzulu _luk__47_ sendhu joopsta sand5pid3r trickle mikenoid beg1nner fladder72 4bsan1ty daitarn z0id0uf amoreno stuntt askkk flyttadig arcsign glavic acid_predator new_0 jala1 crucci niko95 deputydawg optixx ennesit martianbuddy b4r r1dah gathion function9 chup4 poocamshot shnipzr heppo b4byb34r the_hulk

        Thanks for taking the time to test and correct my script.

        Unfortunately, this still "crashes" before the desired end. Here are the errors (if it helps, these appeared at the 24th player):

        command timed-out at /Library/Perl/5.10.0/MozRepl/Client.pm line 186 (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "is_debug" on an undefined value at + /Library/Perl/5.10.0/MozRepl/Client.pm line 188, <MATCH> line 7714 d +uring global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "execute" on an undefined value at +/Library/Perl/5.10.0/MozRepl.pm line 372, <MATCH> line 7714 during gl +obal destruction. (in cleanup) Can't call method "cmd" on an undefined value at /Lib +rary/Perl/5.10.0/MozRepl/Client.pm line 186, <MATCH> line 7714 during + global destruction.

        Even if this still doesn't work as intended, I'm really grateful you are helping me.