Skip Menu |

This queue is for tickets about the POE CPAN distribution.

Report information
The Basics
Id: 35625
Status: resolved
Priority: 0/
Queue: POE

People
Owner: Nobody in particular
Requestors: kr1shnakk [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.0001
Fixed in: (no value)



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}; }
From: acferen [...] yahoo.com
On Sun May 04 23:29:55 2008, kr1shnakk wrote: Show quoted text
> 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.
Getting POE::Wheel::Run two work consistently on Win32 and Linux has been an adventure for me too. Attached is a modified version of your script that works for me (tested on Ubuntu and XP). It requires you to do a little more bookkeeping, but it works. Basically I just use a POE::Filter::Reference to communicate the pid back to the main POE loop and kill it from there. I think Wheel::Run probably can and should deal with this little song and dance, but until someone has time to figure out why it doesn't this should work.
#!perl -w use strict; use warnings; use POE qw(Wheel::Run Filter::Reference); POE::Session->create(inline_states => { _start => \&start, stop => \&stop, handle_task_result => \&handle_task_result, handle_task_debug => \&handle_task_debug, }, ); $poe_kernel->run; sub start { my ($heap, $session, $kernel) = @_[HEAP, SESSION, KERNEL]; print "Starting child\n"; $heap->{task} = POE::Wheel::Run->new( Program => sub { a_task('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 ($heap->{pid})\n"; kill(9, $heap->{pid}); ### kill the child process #$heap->{task}->kill(); delete $heap->{task}; delete $heap->{pid}; } sub handle_task_result { my $result = $_[ARG0]; $_[HEAP]->{pid} = $result->{pid} if $result->{pid}; } 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}; } sub a_task { my $task = shift; binmode(STDOUT); # Required for this to work on MSWin32 my $filter = POE::Filter::Reference->new(); my (%result, $output); my ($pid, $status); $pid = open(my $prgfh, '-|', qq{perl $task}); # $task %result = ( state => 'running', pid => $pid, task => $task ); $output = $filter->put( [ \%result ] ); print STDOUT @$output; close($prgfh); # wait for result %result = ( state => 'finished', pid => $pid, task => $task, res => $? ); $output = $filter->put( [ \%result ] ); print STDOUT @$output; }
Hello, I noticed that BinGOs, the maintainer of POE::Wheel::Run::Win32 released v0.10 to CPAN with this changelog: - Fixed kill() method. I did some tests on my windows VM and it seemed to make the problem go away. If it does help please let BinGOs know and thank him for continuing to maintain POE::Wheel::Run::Win32! NOTE: I had to change Program to Program => [ qw( perl loop.pl ) ] to get the intended results. I noticed my process count jumping from 20 to 22 and back to 20 when the program terminated. Could you please re-test with the latest POE/Wheel::Run::Win32 and let us know your experience? I hope the results are positive so we don't have to employ the workaround suggested by acferen :) If you get a different result please file a new bug against POE::Wheel::Run::Win32 because it's doubtful that we will mangle POE::Wheel::Run to work with Win32 anytime soon ;) -- ~Apocalypse
On Mon Feb 09 19:11:04 2009, APOCAL wrote: Show quoted text
> Hello, > > I noticed that BinGOs, the maintainer of POE::Wheel::Run::Win32 > released v0.10 to CPAN with this changelog: > > - Fixed kill() method. > > I did some tests on my windows VM and it seemed to make the problem go > away. If it does help please let BinGOs know and thank him for > continuing to maintain POE::Wheel::Run::Win32! >
[krishnakk] I will do! Believe it or not, I checked for the updates against this module just 2-3 weeks back and thought nothing has changed. Show quoted text
> NOTE: I had to change Program to Program => [ qw( perl loop.pl ) ] to > get the intended results. I noticed my process count jumping from 20 to > 22 and back to 20 when the program terminated. > > Could you please re-test with the latest POE/Wheel::Run::Win32 and let > us know your experience? I hope the results are positive so we don't > have to employ the workaround suggested by acferen :)
[kr1shnakk] Thanks for the update and as you mentioned I tried with the updated build and it seems to work without a problem with my basic test. Show quoted text
> > If you get a different result please file a new bug against > POE::Wheel::Run::Win32 because it's doubtful that we will mangle > POE::Wheel::Run to work with Win32 anytime soon ;)
[kr1shnakk] I will try more of my tests and let you all know.
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.