Hello. I have a script I have used to encode video for years now. All of a sudden, after an OS update, wine decides it's not going to behave nicely when running more than once. So I figured out that I needed to create a second WINEPREFIX to use. Now the trouble I am having is that I cannot figure out a way to know which ForkManager "slot" I am running under, to give a command as to which WINEPREFIX directory to use. The variable for the slot seems to change between execution time. This would all work if each video encoded literally the same amount of time, but they don't, so I can't do a simple flip-flop with that slot number. I'm not super proficient at coding. Never was. I can get by, but this is absolutely stumping me. Please help.
$slot = 1; my $pm = new Parallel::ForkManager( 2 ); foreach $key ( sort { lc $a cmp lc $b || $a cmp $b } keys %array ) { if( $slot == 2 ){ $slot = 1; } elsif( $slot == 1 ){ $slot = 2; } $pm->start and next; if( ! -e "/mnt/storage/videotemp/$key.hevc" ) { $cmd = 'WINEPREFIX=~/.wine64_'.$slot.' wine ... ; print "\n$cmd\n\n"; exec($cmd); } $pm->finish; } $pm->wait_all_children;
That is just the flip-flop version I thought would work until I ran it and the first video was a long one (6 hours) and the rest were 1 hour videos. I also have been tinkering around with a test file and doing a sleep timer to simulate things:
@data = ( 10,4,20,2,15,6 ); %slot = ( 'one' => 'unoccupied', 'two' => 'unoccupied' ); my $pm = new Parallel::ForkManager( 2 ); DATA_LOOP: foreach my $n (@data) { if ( $slot{ 'one' } eq 'unoccupied' ) { $slotnow = 'one'; $slot{ ' +one' } = 'occupied'; } elsif ( $slot{ 'two' } eq 'unoccupied' ) { $sl +otnow = 'two'; $slot{ 'two' } = 'occupied'; } $pm->start and next DATA_LOOP; print $slotnow." sleep($n)\n"; system( "sleep $n" ); #print "- $slot{$slotnow} - $n\n"; $slot{ $slotnow } = 'unoccupied'; #print Dumper( %slot ); $pm->finish; } $pm->wait_all_children;
I just can't get that test file to kick back to slot one when it is told to. It seems like it is being evaluated correctly at the if statement, but after than it loses what $slotnow and $slot{#} were told to become. I really don't understand what is going on. Is there nothing that is a part of ForkManager to tell which slot is being used? Thank you.

In reply to figuring out Parallel::ForkManager slots by ramicio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.