On Fri, Dec 07, 2001 at 11:17:14AM -0500, Jason Boxman wrote:
> On Friday 07 December 2001 07:02 am, you wrote:
> <snip>
> >
> > > I use STDERR to signal The Wheel::Run's job completion as I'm using
> > > STDOUT as a data stream channel. When I get a specific 'done' event from
> > > STDERR I kill the wheel. I guess it's possible the STDERR event is
> > > caught before the STDOUT pipe is flushed. The sleep 2; fixed this in
> > > most instances, but I still end up with lost data 5-10% of the time.
> >
> > Please do not do things like that. You cannot avoid races with delays, even
> > if they are really big. You should be happy instead, that you found it :)
> > Is this behaviour because input events now go through the queue, and
> > signals not ? Or did I miss something ...
>
> my $coderef = sub {
> my( $request ) = $_[0];
> my $sent_header = 0;
> my $agent = LWP::UserAgent->new( timeout => 45 );
> my $response = $agent->request($request, sub { &data(\$sent_header, @_) },
> 2048);
> .... deal with possible responses ...
> sleep 2;
> }
>
> Later...
>
> sub _start {
> .... lots of tests on things ...
> .... decided I need to run Wheel::Run ....
>
> $self->{run} = POE::Wheel::Run->new(
> Program => sub { $coderef->( $self->{request} ) },
> StdoutEvent => 'stdout',
> StderrEvent => 'stderr',
> Filter => POE::Filter::Stream->new()
> );
>
> Where would I be calling delay? It seems to me I'd need to replace my sleep
> call with it, but that coderef knows nothing of POE and it's running in a
> child process. Should I be passing off KERNEL to $coderef->( ) and calling
> delay from within the coderef?
I was talking about delays in general. It's the sleep in your example. If I
understand it correctly, you delay the end of your program and thus the time
the sigchld is delivered. Delays (sleep()'s) are not useful in this case,
since you never know when the parent process gets scheduled and has a
chance to work on it. The user might even suspend it and your program
would have to work as well. The signal is probably delivered before the
events get through the queue, but please check wether they are delivered
synchronously because I don't know if I remember that correctly.
Torvald