Re: POE::Wheel::Run ErrorEvent
On Mon, Feb 17, 2003 at 07:02:41PM -0500, Wiggins d'Anconia wrote: > > Rocco Caputo wrote: > >On Wed, Feb 12, 2003 at 08:38:25AM +1100, [EMAIL PROTECTED] wrote: > > > > > > >It's a valid interpretation of ErrorEvent, but it's not the way > >POE::Wheel::Run was written. > > > >StdoutEvent, StderrEvent, and ErrorEvent refer to the pipes that > >attach the parent and child processes. The first two provide child > >output that is received on those pipes, and the third lets you know if > >there are errors reading from them. > > > >A child program's return value comes to you differently: through > >SIGCHLD. If it's significant, you'll need to set up a SIGCHLD handler > >and match the returned process ID against the process ID of your > >active wheel. [sample code for using a CHLD signal handler to catch return values] > Should the above be added to the POE::Wheel::Run docs or on the cookbook > page possibly? I think this is a good example of what should be done, > and was also confused by how the docs are worded. It also appeared to > me that the "CloseEvent" was *the* way to find out that the process was > complete, when clearly it is really just when STDOUT is closed, granted > this should happen when the process is over. I haven't had a chance to > work the above into my app yet but it definitely closes one question I > had lingering Probably yes. There also needs to be a tutorial on POE::Component::Child, which supplies a lot of the support code you might otherwise need to write for POE::Wheel::Run. It even handles SIGCHLD for you, supplying a "died" event that includes the return code. If anybody would like to supply a POE::Component::Child example for the cookbook, please do. -- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/
Re: POE::Wheel::Run ErrorEvent
Rocco Caputo wrote: On Wed, Feb 12, 2003 at 08:38:25AM +1100, [EMAIL PROTECTED] wrote: It's a valid interpretation of ErrorEvent, but it's not the way POE::Wheel::Run was written. StdoutEvent, StderrEvent, and ErrorEvent refer to the pipes that attach the parent and child processes. The first two provide child output that is received on those pipes, and the third lets you know if there are errors reading from them. A child program's return value comes to you differently: through SIGCHLD. If it's significant, you'll need to set up a SIGCHLD handler and match the returned process ID against the process ID of your active wheel. sub _start_handler { my $kernel = $_[KERNEL]; $kernel->sig( CHLD => "sig_chld" ); my $heap = $_[HEAP]; my $wheel = POE::Wheel::Run->new( ... ); # Map PID to wheel reference here. Useful for managing multiple # child processes in the same session. $heap->{wheels}{$wheel->PID} = $wheel; } # ARG1 contains the PID of the ended child process. # ARG2 contains the $? (perlvar) associated with this CHLD signal. sub sig_chld_handler { my ($pid, $return_value) = @_[ARG1, ARG2]; my $wheel = delete $_[HEAP]->{wheels}{$pid}; if (defined $wheel) { print "Process $pid returned $return_value.\n"; } } Should the above be added to the POE::Wheel::Run docs or on the cookbook page possibly? I think this is a good example of what should be done, and was also confused by how the docs are worded. It also appeared to me that the "CloseEvent" was *the* way to find out that the process was complete, when clearly it is really just when STDOUT is closed, granted this should happen when the process is over. I haven't had a chance to work the above into my app yet but it definitely closes one question I had lingering http://danconia.org
Re: POE::Wheel::Run ErrorEvent
On Wed, Feb 12, 2003 at 08:38:25AM +1100, [EMAIL PROTECTED] wrote: > > That output indicates ErrorEvent has been triggered twice. The first > > time when the child process closes STDERR, and the second time when it > > closes STDOUT. I added some extra output to the sample code: > > Based upon your earlier comments, this is as I had expected. What does > concern me however is that the dying of the executed program, which an > associated error return value, is not triggering an error event. > > my $task = POE::Wheel::Run->new( > 'Program' => 'perl -e "die"', > 'CloseEvent'=> 'close', > 'ErrorEvent'=> 'error', > 'StderrEvent' => 'output', > 'StdoutEvent' => 'output', > 'StderrFilter' => POE::Filter::Stream->new, > 'StdoutFilter' => POE::Filter::Stream->new > ); > > This I would expect should trigger an error event - Or are my expectations > incorrect here? Alternatively, what would be another way to obtain the > return value for a program executed through POE::Wheel::Run? It's a valid interpretation of ErrorEvent, but it's not the way POE::Wheel::Run was written. StdoutEvent, StderrEvent, and ErrorEvent refer to the pipes that attach the parent and child processes. The first two provide child output that is received on those pipes, and the third lets you know if there are errors reading from them. A child program's return value comes to you differently: through SIGCHLD. If it's significant, you'll need to set up a SIGCHLD handler and match the returned process ID against the process ID of your active wheel. sub _start_handler { my $kernel = $_[KERNEL]; $kernel->sig( CHLD => "sig_chld" ); my $heap = $_[HEAP]; my $wheel = POE::Wheel::Run->new( ... ); # Map PID to wheel reference here. Useful for managing multiple # child processes in the same session. $heap->{wheels}{$wheel->PID} = $wheel; } # ARG1 contains the PID of the ended child process. # ARG2 contains the $? (perlvar) associated with this CHLD signal. sub sig_chld_handler { my ($pid, $return_value) = @_[ARG1, ARG2]; my $wheel = delete $_[HEAP]->{wheels}{$pid}; if (defined $wheel) { print "Process $pid returned $return_value.\n"; } } -- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/
RE: POE::Wheel::Run ErrorEvent
> That output indicates ErrorEvent has been triggered twice. The first > time when the child process closes STDERR, and the second time when it > closes STDOUT. I added some extra output to the sample code: Based upon your earlier comments, this is as I had expected. What does concern me however is that the dying of the executed program, which an associated error return value, is not triggering an error event. my $task = POE::Wheel::Run->new( 'Program' => 'perl -e "die"', 'CloseEvent'=> 'close', 'ErrorEvent'=> 'error', 'StderrEvent' => 'output', 'StdoutEvent' => 'output', 'StderrFilter' => POE::Filter::Stream->new, 'StdoutFilter' => POE::Filter::Stream->new ); This I would expect should trigger an error event - Or are my expectations incorrect here? Alternatively, what would be another way to obtain the return value for a program executed through POE::Wheel::Run? Regards, Rob Rob Casey Implementation Analyst Essential and Direct Mail Development Hermes Precisa Australia (Victoria) Phone : (03) 9217-5501 Email : [EMAIL PROTECTED] -Original Message- From: Rocco Caputo [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 12, 2003 12:10 AM To: [EMAIL PROTECTED] Subject: Re: POE::Wheel::Run ErrorEvent On Tue, Feb 11, 2003 at 02:05:55PM +1100, [EMAIL PROTECTED] wrote: > > 2. I am surprised that ErrorEvent is not triggered in that case. Are > > you using POE 0.25? If there is a problem in Wheel::Run, it would > > help greatly if you could submit a test case that reproduces it. > > I was running 0.24 on my system - I have updated this to 0.2501 from CVS and > the error persists. > > robin:/users/rc6286/workspace/dev/perl/pas > perl test.perl > Output: Died at -e line 1. > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDERR'; > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDOUT'; That output indicates ErrorEvent has been triggered twice. The first time when the child process closes STDERR, and the second time when it closes STDOUT. I added some extra output to the sample code: [...] 'close' => sub { delete $_[ HEAP ]->{'_task'}; print "closed\n"; }, 'error' => sub { print "error:\n",Dumper( @_[ ARG0 .. ARG4 ] ) }, Here's the new output, first using perl 5.005_03, and then using 5.6.1. 2) eyrie:~/public_html/tmp% perl5.00503 robt-casey-errorevent.perl Output: Died at -e line 1. error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDOUT'; error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDERR'; closed 2) eyrie:~/public_html/tmp% perl robt-casey-errorevent.perl Output: Died at -e line 1. error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDERR'; error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDOUT'; closed -- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/ ** IMPORTANT The contents of this e-mail and its attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you received this e-mail in error, please notify the HPA Postmaster, [EMAIL PROTECTED], then delete the e-mail. This footnote also confirms that this e-mail message has been swept for the presence of computer viruses by MimeSweeper. Before opening or using any attachments, check them for viruses and defects. Our liability is limited to resupplying any affected attachments. HPA collects personal information to provide and market our services. For more information about use, disclosure and access see our Privacy Policy at www.hpa.com.au **
Re: POE::Wheel::Run ErrorEvent
On Tue, Feb 11, 2003 at 02:05:55PM +1100, [EMAIL PROTECTED] wrote: > > 2. I am surprised that ErrorEvent is not triggered in that case. Are > > you using POE 0.25? If there is a problem in Wheel::Run, it would > > help greatly if you could submit a test case that reproduces it. > > I was running 0.24 on my system - I have updated this to 0.2501 from CVS and > the error persists. > > robin:/users/rc6286/workspace/dev/perl/pas > perl test.perl > Output: Died at -e line 1. > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDERR'; > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDOUT'; That output indicates ErrorEvent has been triggered twice. The first time when the child process closes STDERR, and the second time when it closes STDOUT. I added some extra output to the sample code: [...] 'close' => sub { delete $_[ HEAP ]->{'_task'}; print "closed\n"; }, 'error' => sub { print "error:\n",Dumper( @_[ ARG0 .. ARG4 ] ) }, Here's the new output, first using perl 5.005_03, and then using 5.6.1. 2) eyrie:~/public_html/tmp% perl5.00503 robt-casey-errorevent.perl Output: Died at -e line 1. error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDOUT'; error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDERR'; closed 2) eyrie:~/public_html/tmp% perl robt-casey-errorevent.perl Output: Died at -e line 1. error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDERR'; error: $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDOUT'; closed -- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/
RE: POE::Wheel::Run ErrorEvent
> 2. I am surprised that ErrorEvent is not triggered in that case. Are > you using POE 0.25? If there is a problem in Wheel::Run, it would > help greatly if you could submit a test case that reproduces it. I was running 0.24 on my system - I have updated this to 0.2501 from CVS and the error persists. robin:/users/rc6286/workspace/dev/perl/pas > perl test.perl Output: Died at -e line 1. $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDERR'; $VAR1 = 'read'; $VAR2 = '0'; $VAR3 = ''; $VAR4 = 2; $VAR5 = 'STDOUT'; robin:/users/rc6286/workspace/dev/perl/pas > cat test.perl use Data::Dumper; use POE; use POE::Filter::Stream; use POE::Wheel::Run; use strict; POE::Session->create( 'inline_states' => { '_start'=> sub { my $task = POE::Wheel::Run->new( 'Program' => 'perl -e "die"', 'CloseEvent'=> 'close', 'ErrorEvent'=> 'error', 'StderrEvent' => 'output', 'StdoutEvent' => 'output', 'StderrFilter' => POE::Filter::Stream->new, 'StdoutFilter' => POE::Filter::Stream->new ); $_[ HEAP ]->{'_task'} = $task; }, '_stop' => sub {}, 'close' => sub { delete $_[ HEAP ]->{'_task'} }, 'error' => sub { print Dumper( @_[ ARG0 .. ARG4 ] ) }, 'output'=> sub { print "Output: ", $_[ ARG0 ] } } ); $poe_kernel->run; exit 0; robin:/users/rc6286/workspace/dev/perl/pas > perl -MPOE -le 'print $POE::VERSION' 0.2501 For reference: robin:/users/rc6286/workspace/dev/perl/pas > perl -V Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=solaris, osvers=2.8, archname=sun4-solaris uname='sunos localhost 5.8 sun4u sparc sunw,ultra-1 ' hint=previous, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-xO3 -xdepend', gccversion= cppflags='' ccflags ='' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 alignbytes=8, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags ='' libpth=/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-R /usr/perl5/5.00503/sun4-solaris/CORE' cccdlflags='-KPIC', lddlflags='-G' Characteristics of this binary (from libperl): Built under solaris Compiled at Dec 22 1999 00:00:57 %ENV: PERL5LIB="/users/rc6286/workspace/dev/perllibs" PERL5LIBS="/users/rc6286/workspace/dev/perllibs" @INC: /users/rc6286/workspace/dev/perllibs/sun4-solaris /users/rc6286/workspace/dev/perllibs /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 . Is there anything else which I can provide or try out to help? Regards, Rob Rob Casey Implementation Analyst Essential and Direct Mail Development Hermes Precisa Australia (Victoria) Phone : (03) 9217-5501 Email : [EMAIL PROTECTED] -Original Message- From: Rocco Caputo [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 11, 2003 1:23 PM To: [EMAIL PROTECTED] Subject: Re: POE::Wheel::Run ErrorEvent ** IMPORTANT The contents of this e-mail and its attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you received this e-mail in error, please notify the HPA Postmaster, [EMAIL PROTECTED], then delete the e-mail. This footnote also confirms that this e-mail message has been swept for the presence of computer viruses by MimeSweeper. Before opening or using any attachments, check them for viruses and defects. Our liability is limited to resupplying any affected attachments. HPA collects personal information to provide and market our services. For more information about use, disclosure and access see our Privacy Policy at www.hpa.com.au **
Re: POE::Wheel::Run ErrorEvent
On Tue, Feb 11, 2003 at 11:05:48AM +1100, [EMAIL PROTECTED] wrote: > I seem to be having an ErrorEvent triggered within POE::Wheel::Run upon the > end of the input from STDERR and STDOUT. eg. > > sub _error { > my ( $syscall, $errno, $error, $id, $handle ) = @_[ ARG0 .. ARG4 ]; > print Dumper( $syscall, $errno, $error, $id, $handle ); > } > > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDERR'; > $VAR1 = 'read'; > $VAR2 = '0'; > $VAR3 = ''; > $VAR4 = 2; > $VAR5 = 'STDOUT'; > > Firstly, is this expected? Secondly, when I have an executable that dies > during execution (eg. Program => 'perl -e "die q/ horribly /;"'), the > ErrorEvent is not triggered. > > Any ideas? 1. It is expected. Most operating systems report read error 0 to signify the end of a file. 2. I am surprised that ErrorEvent is not triggered in that case. Are you using POE 0.25? If there is a problem in Wheel::Run, it would help greatly if you could submit a test case that reproduces it. -- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/