saintmike has asked for the wisdom of the Perl Monks concerning the following question:

I don't seem to get POE::Wheel::Run working with a subroutine. It's emitting text to STDOUT, which should trigger a "captured" event in POE. Oh mighty perlmonks, do you know why the script below never reaches the "captured" state?
2006/06/04 21:36:44 child sleeping 2006/06/04 21:36:44 done printing
use POE qw(Wheel::Run); use Log::Log4perl qw(:easy); Log::Log4perl->easy_init({ level => $DEBUG, file => ">>/tmp/wheel.log"}); POE::Session->create( inline_states => { _start => sub { my $w = POE::Wheel::Run->new( Program => sub { DEBUG "child sleeping"; $|++; print "foo\n"; DEBUG "done printing"; sleep 10; }, StdoutEvent => "captured", )}, captured => sub { my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1]; DEBUG "Child process in wheel $wheel_id wrote to STDOUT: $input" +; } } ); POE::Kernel->run();

Replies are listed 'Best First'.
Re: POE::Wheel::Run and StdoutEvent
by saintmike (Vicar) on Jun 05, 2006 at 16:24 UTC
    Someone from the POE mailing list pointed out the problem: The wheel goes out of scope. Making $w a global seems to fix the problem.

      A better solution would be to store the wheel object in the session's heap, since wheels are tightly coupled to their sessions.

        By using:

        $_HEAP->{theWheel} = POE::Wheel::Run->new(...)

        The console print is captured, but the app hangs and never returns. Is it normal for POE to still run after the subroutine has slept and is over ?

        I just looked at the preview of this reply and the msg formatter prints the HEAP var in a funny manner.