Update: Removing the shared hash code solves the hanging process problem, see below.

Unfortunately this, too, simply hangs on interrupt:

PID 28907 Forked worker in slot 2 with pid 28910 for chunk 1 Forked worker in slot 1 with pid 28909 for chunk 2 After 1: $VAR1 = { '00 28910' => '1491580974', '01 28909' => '1491580974' }; After 0: $VAR1 = { '00 28910' => '1491580974', '01 28909' => '1491580974' }; Forked worker in slot 1 with pid 28909 for chunk 3 Forked worker in slot 2 with pid 28910 for chunk 4 After 2: $VAR1 = { '00 28910' => '1491580974', '01 28909' => '1491580974', '02 28909' => '1491580975' }; After 3: $VAR1 = { '00 28910' => '1491580974', '01 28909' => '1491580974', '02 28909' => '1491580975', '03 28910' => '1491580975' }; ^CHello from INT Hello from INT Hello from INT
... hangs here ... all three processes alive:
pgr mce nickt 28907 01:26 perl mce4.pl nickt 28909 01:26 perl mce4.pl nickt 28910 01:26 perl mce4.pl

I am running on Debian, Perl 5.16.3, with the very latest MCE modules.

Thank you.

Update: Note that if I simply comment out all the shared hash code, the program can be interrupted and the processes do not hang, but the END block is never reached:

perl mce4.pl PID 29593 Forked worker in slot 2 with pid 29596 for chunk 1 Forked worker in slot 1 with pid 29595 for chunk 2 Forked worker in slot 1 with pid 29595 for chunk 4 Forked worker in slot 2 with pid 29596 for chunk 3 ^CHello from INT Worker is ready to dump Hello from INT Parent is ready to dump Hello from INT Worker is ready to dump ## mce4.pl: caught signal (INT), exiting Killed
... above with this code:
use strict; use warnings; use feature 'say'; use Data::Dumper; ++$Data::Dumper::Sortkeys; use MCE::Shared; use MCE::Loop; $|++; my $pid = $$; say "PID $pid"; my $mutex = MCE::Mutex->new(); #tie my %hash, 'MCE::Shared', (); $SIG{'INT'} = sub { my $signal = shift; say 'Hello from INT'; # if ( tied(%hash)->len ) { (MCE->wid == 0) ? say 'Parent is ready to dump' : say 'Worker is ready to dump'; # say 'Dumping: ' . Dumper \%hash; # %hash = (); # } MCE::Signal::stop_and_exit($signal); }; $SIG{'TERM'} = sub { my $signal = shift; say 'Hello from TERM'; if (MCE->wid > 0) { # worker MCE->exit(0); } else { # parent say 'Parent is ready to dump'; # say 'Dumping: ' . Dumper \%hash; MCE::Signal::stop_and_exit($signal); } }; MCE::Loop->init( max_workers => 2, chunk_size => 1 ); mce_loop { my ( $mce, $chunk_ref, $chunk_id ) = @_; say sprintf 'Forked worker in slot %s with pid %s for chunk %s', M +CE->wid, MCE->pid, $chunk_id; for ( @{ $chunk_ref } ) { # $hash{ sprintf '%.2d %s', $_, $$ } = time; $mutex->synchronize( sub { # say "After $_: " . Dumper \%hash; }); sleep 1; } } ( 0 .. 4 ); MCE::Loop->finish; END { say sprintf '%s %s (%s) in END', $$, time, $$ == $pid ? 'Parent' : + 'Child'; if ( MCE->wid == 0 or $$ == $pid ) { say "Parent is ready to dump"; # say 'Dumping: ' . Dumper \%hash; } }


The way forward always starts with a minimal test.

In reply to Re^5: Interrupt multi-process program while using MCE::Shared hash: END block code does not (all) run by 1nickt
in thread Interrupt multi-process program while using MCE::Shared hash: END block code does not (all) run by 1nickt

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.