Without commenting on the design of this, it does seem like you have a
typo in your start_tasks sub:

my $delay_id    = $poe_kernel->delay_set("task_kill",$timeout,$task);

should be:

my $delay_id    = $poe_kernel->delay_set("task_kill",$timeout,$task->ID);

After the change it seems to start working. I think you were catching
the wrong thing on your ARG0 in the task_kill handler. See?

On 6/7/05, phaidros <[EMAIL PROTECTED]> wrote:
> hi gurus, ; )
> 
> I have taken an example from the cookbook and modified it, that it
> handles the childs after a certain timout. they shall get killed and the
> kernel shall end.
> I still have problems that the kernel never returns. I have read alot of
> urls friendly people pointed me to in #poe, but still are questions open.
> runninf the script with sub POE::Kernel::TRACE_REFCNT () { 1 }, shows me
> int the end 1 open event and 5 Files.
> I think the event is the sighandler I set up and the files are the
> Filter::References(?).
> as I'm not able to find out, how to address the left events and files to
> dereference, this as my question here:
> how do I get rid of the balast the kernel still is carriyng around?
> 
> the code comes here:
> 
> #!/usr/bin/perl -w
> 
> $|=1; #unbuffered input
> 
> use strict;
> use warnings;
> 
> #sub POE::Kernel::TRACE_REFCNT () { 1 }
> use POE qw(Wheel::Run Filter::Reference);
> 
> our %alarms;
> my @tasks = ("1_1","2_2","3_3","4_2","5_1");
> my $count       = scalar @tasks;
> print "we have $count tasks to do\n";
> sub MAX_CONCURRENT_TASKS () { $count }
> 
> # variables and stuff done here
> 
> POE::Session->create
>   ( inline_states =>
>       { _start => \&start_tasks,
>         next_task   => \&start_tasks,
>         task_result => \&handle_task_result,
>         task_done   => \&handle_task_done,
>         task_debug  => \&handle_task_debug,
>         task_kill       => \&handle_task_done,
>       }
>   );
> 
> sub start_tasks {
>     my $heap = $_[HEAP];
>     $poe_kernel->sig(CHLD => 'reaper');
>     while ( keys( %{ $heap->{task} } ) < MAX_CONCURRENT_TASKS ) {
>         my $next_task = shift @tasks;
>         last unless defined $next_task;
>         my @task_args = split(/_/, $next_task);
>         my $task = POE::Wheel::Run->new
>           ( Program      => sub { do_stuff($task_args[0], $task_args[1]) },
>             StdoutFilter => POE::Filter::Reference->new(),
>             StdoutEvent  => "task_result",
>             StderrEvent  => "task_debug",
>             CloseEvent   => "task_done",
>           );
>         print "wheel $task is running with: name \"$task_args[0]\" and
> param \"$task_args[1]\"\n";
>                 my $timeout             = 2;
>         my $delay_id    = $poe_kernel->delay_set("task_kill",$timeout,$task);
>                 $alarms{$task} = $delay_id ;
>         $heap->{task}->{ $task->ID }    = $task;
>     }
> }
> 
> sub reaper {
>     my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
>     if ($heap->{task}->ID ) {
>         print STDERR "child has died prematurely\n";
>     } else {
>         print STDERR "child has completed when the counter ran out\n";
>     }
>     #($self->{task}->ID) = undef;
>     $kernel->sig_handled;
> }
> 
> sub regx{
>         #do sumthing
>         my $result = shift;
>         return("done");
> }
> 
> sub do_stuff {
>     my $name            = shift;
>     my $param           = shift;
>     my $filter          = POE::Filter::Reference->new();
>     # some dummy action here
>     my $ergebnis        = regx($name);
>     my %result          =
>       ( task            => $name,
>         status          => "$ergebnis"
>       );
>     my $output          = $filter->put( [ \%result ] );
>     print @$output;
> }
> 
> sub handle_task_result {
>     my $result = $_[ARG0];
>     print "$result->{task} returned: $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};
> }
> 
> sub handle_task_kill {
>     my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ];
>     $kernel->refcount_decrement( $heap->{task}->{$task_id} );
>     $task_id->kill();
>     delete $heap->{task}->{$task_id};
>     my $delay_id = $alarms{$task_id};
>     $kernel->alarm_remove($delay_id);
> }
> 
> $poe_kernel->run();
> print STDERR "kernel now finished. we can continue with sumthin else\n";
> exit 0;
> 
> 
> 
> regards,
> phai
> 
> --
> better burn out than fade away ..
>

Reply via email to