Re: run an interactive command using POE::Wheel?

"woosley. xu." <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
ctrl-c gives a INT signal which is captured by the sub below. When the
ctrl-c is captured, the code will kill the job with signal TERM, this should
generate a SIGCHLD and make the wheel to exit, not in  the state of
"zombie".

sub read_from {
    my ($input, $exception) = @_[ARG0, ARG1];
    my $console = $_[HEAP]->{stdin};
    my $job     = $_[HEAP]->{job};
    unless (defined $input) {
        $console->put("Exception got, existing....");
        $job && $job->kill();
        return;
    }
    $_[HEAP]->{stdin}->put("got: $input");
    $_[HEAP]->{job}->put($input);
}

2009/9/28 Olivier Mengué <[email protected]>

>
> > *POE::Kernel::USE_SIGCHLD = sub (){1};
>
> If you want this line to be effective, you have to put it ABOVE the "use
> POE" line.
> And it is better written that way:
> sub POE::Kernel::USE_SIGCHLD { 1 }
> The way you wrote it would be less efficient as I expect the function would
> not be inlined as a constant.
>
>
> > Below is my code. If I input CTRL-C when the script asking for a username
> or
> > password, the script dose not exit even if I use $SIG{CHLD}='IGNORE'. By
> 'ps
> > -ef', I can see that the get_name.pl is in the state of  "zombie" and
> > waiting for the parent process to reap.
>
> CTRL+C gives SIGBREAK, not SIGCHLD.
> You are correctly handling SIGCHLD in on_child_signal, except, as Nick
> pointed:
>    $_[KERNEL]->sig_child($pid, 'got_child_signal');
>
> You should add a SIGBREAK handler in on_start:
>  $poe_kernel->sig(BREAK => 'on_sig_term');
>  $poe_kernel->sig(TERM => 'on_sig_term');
>
> sub on_sig_term
> {
>   if (exists $_[HEAP]->{job}) {
>     $_[HEAP]->{job}->kill();
>     delete $_[HEAP]->{job};
>   }
>   delete $_[HEAP]->{stdin};
>   $poe_kernel->sig_handled();
> }
>
> Olivier.
>
>


-- 
Woosley.Xu
Tju->PMO->Rdps
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.