Okay, I see the issue. The shared-manager process is exiting from receiving the signal. Thus, not able to respond to later requests. Hence stalling the script.
Inside MCE::Shared::Server.pm around line 461, comment out the handler code and add the subsequent line. Basically, the shared-manager must still respond to requests inside application handlers. I'm not sure if I can handle both cases. This handler was placed here in the event something killed the shared-manager process.
sub _loop {
$_is_client = 0;
# $SIG{HUP} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
# $SIG{INT} = $SIG{$_[0]} = sub { };
#
# CORE::kill($_[0], $_is_MSWin32 ? -$$ : -getpgrp);
# for my $_i (1..15) { sleep 0.060 }
#
# CORE::kill('KILL', $$);
# CORE::exit(255);
# };
$SIG{HUP} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub { };
...
}
I've simplyfied the handling for the MCE script.
use strict; use warnings; use feature 'say';
use Data::Dumper; ++$Data::Dumper::Sortkeys;
use Time::HiRes 'sleep';
use MCE::Loop;
use MCE::Shared;
$|++;
my $pid = $$; say "PID $pid";
my $hash = MCE::Shared->hash();
$SIG{'INT'} = $SIG{'TERM'} = sub {
my $signal = shift; $SIG{'INT'} = $SIG{'TERM'} = sub {};
say "Hello from $signal: $$";
say 'Parent is ready to dump';
say 'Dumping: ' . Dumper $hash->export;
MCE::Signal::stop_and_exit('INT');
};
MCE::Loop->init(
max_workers => 2, chunk_size => 1, user_begin => sub {
$SIG{'INT'} = sub {
my $signal = shift;
say "Hello from $signal: $$";
MCE->exit(0);
};
$SIG{'TERM'} = sub {
my $signal = shift;
say "Hello from $signal: $$";
MCE::Signal::stop_and_exit($signal);
};
}
);
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;
say "After $_: " . Dumper $hash->export;
sleep 2;
}
} ( 0 .. 12 );
MCE::Loop->finish;
say "Parent is ready to dump";
say 'Dumping: ' . Dumper $hash->export;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.