Closed chrisdenley closed 7 years ago
Thank you for the bug report. Do you have a small use case so that I can ensure validation. For example, where are you setting $? ?. Inside handler, inside worker?
Regards,
#!/opt/perl/bin/perl
use strict;
use MCE::Signal qw(-no_kill9);
use MCE;
if($ARGV[0] ne 'test') {
print "parent PID is $$\n";
system($^X,$0,'test');
my $ec = $? >> 8;
print "Child exited with exit code $ec\n";
sleep 2;
print "Parent exiting\n";
exit(0);
}
print "child PID is $$\n";
#setpgrp();
sub forever {
print "Process $$ will wait forever...\n";
sleep 1 while(1);
}
sub inputiter {
return ('a'..'z');
}
my $mce = MCE->new(
max_workers => 2,
chunk_size => 512,
input_data => \&inputiter,
user_func => \&forever,
);
sub sighandle {
$? = -1;
#print "PID $$ SIGNAL ".$_[0]."\n";
#$MCE::Signal::STATUS = $?;
MCE::Signal::stop_and_exit(@_);
}
#$SIG{$_} = \&sighandle foreach(qw(HUP INT PIPE QUIT TERM));
$? = -1; # this will be the exit code if terminated early
print "Running MCE\n";
print "PID $$ \$? = $?\n";
$mce->run();
#$? = 0; # set this back to 0 (no error) after MCE completed successfully
print "PID $$ finished\n";
exit($?);
As you can see, I was also testing with setting the process group (it was killing off my parent process as well). I had tried overriding the signal handler, but ultimately setting $? before the $mce->run() would change the exit code on SIGTERM on the previous version.
This is fixed for the upcoming MCE 1.830 release. Thank you, @chrisdenley.
Your sample code was beneficial. I needed to update the fix applied 2 hours ago. Thanks again.
That was fast! My testing looks good. When should I expect to see this change in CPAN? Thanks!
Definitely soon and no later than the end of August. I have a couple validations to run for science and want to ensure no further changes are needed.
MCE 1.830 was released today containing the fix. Thank you.
I'm trying to troubleshoot a problem with my script hanging intermittently, but the output isn't captured if the exit code is 0 since that indicates there is no error. If the process is killed with a SIGTERM, then it always seems to exit with code 0. I found that with MCE 1.817, I can set $? to change the exit code actually returned. However, with MCE 1.829 that doesn't seem to work.