ground0 has asked for the wisdom of the Perl Monks concerning the following question:
Here I have nested forks with objects created prior to for loops. When $html = $mech->content; and $html .= $mech->content; happens it seem to mix up concurrent $mech object. My result is wrong document elements in my temporary files.
This is an upgrade to my existing production code which only runs one FireFox and does not use multiple FireFox profiles and Mozrepl tcp/ip ports.
for each $country_key (keys %$countries) { $fork_countries->start and next; ... foreach $case_no (keys %$case) { $fork_cases->start and next; #do DBIx stuff to get random $ff_profile / avoid race condition $ff_port = 42420 + $ff_profile; &myMain($ff_profile, $ff_port); $fork_cases->finish; } $fork_cases->wait_all_children; $fork_countries->finish; } $fork_countries->wait_all_children; sub myMain { $mech = WWW::Mechanize::Firefox->new( launch => ['firefox','-P',$ff_profile,-no-remote'], repl => "localhost:$ff_port", bufsize => 10_000_000, tab => 'current', autoclose => 1 ); $mech->get($url); $url = $new_url; ### KLUDGED HERE ### # # $temp = $mech->uri; # (undef, $uri) = split(/(\?.*)/, $temp); # $url .= $uri; # ### $html = $mech->content; $mech->get($url); #or eval, click(), etc. $html .= $mech->content; #open temp filehandle and print $html #(temp filenames padded with String::Random) $mech->get(temp_filename); $png = $mech->content_as_png; #add png to PDF with PDF::API2 #write PDF file }
According to what I can find on Parallel::ForkManager each forked $mech and $html should be separate. However, when the $url is the same in each fork either the $mech object, or the $html scalar get mix up.
Then what happens when I do some other method, say $mech->eval() then $html .= $mech->content; the $html I want to print to temp file is mixed with what I thought should be totally separate FireFox profiles and HTTP sessions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::ForkManager memory mixup?
by Corion (Patriarch) on Mar 28, 2013 at 22:55 UTC | |
by Anonymous Monk on Mar 29, 2013 at 02:11 UTC | |
by ground0 (Novice) on Mar 29, 2013 at 02:19 UTC | |
by ground0 (Novice) on Mar 29, 2013 at 16:48 UTC | |
by ground0 (Novice) on Mar 30, 2013 at 14:07 UTC |