Home > Archive > PERL POE > June 2006 > POE::Wheel::Run and subroutines
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
POE::Wheel::Run and subroutines
|
|
| Mike Schilli 2006-06-05, 7:23 pm |
| 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. 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";
}
}
);
-- Mike
Mike Schilli
m@perlmeister.com
| |
| Chris Fedde 2006-06-05, 7:23 pm |
| The wheel goes out of scope. Making it global will suffice but usually it
gets stuffed into the HEAP. Of course it needs to detect the death of the
child and delete the wheel to order to have a clean shutdown.
On Mon, 5 Jun 2006 07:31:13 -0700 (PDT) Mike Schilli wrote:
+------------------
| 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. 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";
| }
| }
| );
|
| -- Mike
|
| Mike Schilli
| m@perlmeister.com
+------------------
--
Chris Fedde
303 773 9134
| |
| Justin Hawkins 2006-06-05, 7:23 pm |
|
On 06/06/2006, at 1:59 AM, Chris Fedde wrote:
> The wheel goes out of scope. Making it global will suffice but
> usually it
> gets stuffed into the HEAP. Of course it needs to detect the death
> of the
> child and delete the wheel to order to have a clean shutdown.
Ha!
I spent several hours last night puzzling over exactly this, this
morning the answer came to me in a pre-waking thought. What a waste
of neurons, others have asked and answered the problem for me :-)
I think it's worth a mention of this on the POE::Wheel::Run man page,
the example given specifically does *not* save the wheel object, and
it might be assumed by others that it's unnecessary.
The "Of course" makes sense in hindsight, but during my initial
hacking, just trying to get output from a program, that did not occur
to me.
- Justin
--
Justin Hawkins
justin@hawkins.id.au
| |
| Mike Schilli 2006-06-05, 10:09 pm |
| On Tue, 6 Jun 2006, Justin Hawkins wrote:
> Ha!
> I spent several hours last night puzzling over exactly this
Thanks, I appreciate your help :). So obvious in hindsight, but
really hard to figure out without helpful error messages.
-- Mike
Mike Schilli
m@perlmeister.com
|
|
|
|
|