Subject: | POE::Wheel::Run kill() on Windows |
Hi,
I am trying to use POE::Wheel::Run to start and stop another perl
process (loop.pl). I want to be able to kill this process from my main
POE program (test.pl). But it seems like the kill() method of
POE::Wheel::Run doesn't stop the process started. The parent process
terminates but the child process continues to run as a detached
process. I tried the same on Linux FC5 and it seems to run as expected
(kills the child process fine). Also, I tried with
POE::Wheel::Run::Win32 which didn't help either. I would really
appreciate any help at this time.
OS: Windows XP SP2
Active Perl version : v5.8.8 built for MSWin32-x86-multi-thread Build
822
POE package installed version : POE-1.0001
Here is my sample code:
loop.pl:
########
while (1) {sleep 1;}
test.pl:
########
use strict;
use warnings;
use POE qw(Wheel::Run Filter::Reference);
POE::Session->create(inline_states => {
_start => \&start,
stop => \&stop,
}
);
$poe_kernel->run;
sub start {
my ($heap, $session, $kernel) = @_[HEAP, SESSION, KERNEL];
print "Starting child\n";
$heap->{task} = POE::Wheel::Run->new(
Program => 'perl loop.pl',
StdoutFilter => POE::Filter::Reference->new(),
StdoutEvent => "handle_task_result",
StderrEvent => "handle_task_debug",
CloseEvent => "handle_task_done",
);
$kernel->delay(stop => 10);
}
sub stop {
my ($heap, $kernel) = @_[HEAP, KERNEL];
print "Stopping child\n";
$heap->{task}->kill(9); ### kill the child process
delete $heap->{task};
}
sub handle_task_result {
my $result = $_[ARG0];
print "Result for $result->{task}: $result->{status}\n";
}
sub handle_task_debug {
my $result = $_[ARG0];
print "Debug: $result\n";
}
sub handle_task_done {
my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ];
delete $heap->{task}->{$task_id};
}