Re: Net::LDAP and POE

2004-03-11 Thread saint Marck
I just wanted to say that WeakRef is cool...
Right?

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com


RE: small wishes to poe::wheel::run can't figure out.

2004-03-11 Thread Erick Calder
you might also want to look at PoCo::Child for inspiration

-Original Message-
From: Andy Levine [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 09, 2004 3:23 AM
To: [EMAIL PROTECTED]
Subject: RE: small wishes to poe::wheel::run can't figure out.


Michael,
>
> I would like to get an error_level for each program i run in parallel...
Pass the param "ErrorEvent" when you instantiate the POE::Wheel::Run to trap
errors.

> And it would also be nice to get a value back so i can track which program
> that return a
> given answer...
>
I get program exit codes by trapping SIGCHLD to tell when my child process
die. In your 'start' handler, add something like this:

  $kernel->sig(CHLD => '__sig_child');

Then handle the __sig_child event. The program exit code is one of the
parms, as follows:

sub onSIGCHLD {
my($self, $heap, $signalname, $kidPID, $kidRC) =
@_[ OBJECT, HEAP, ARG0..ARG2 ];

> Thanks a lot in advance...
>
> Michael , Denmark.
>
> - snip ---
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use POE;
> use POE::Wheel::Run;
>
> my $time1=time();
>
> # Start a multitasking session to manage several child processes.  Map
> # each event to a function which will handle it.  Run POE::Kernel,
> # which manages the session's activity.  run() will return when the
> # session is done, and so we exit.
>
>
> POE::Session->new
>   ( _start => \&start_processes,
> process_stdout => \&read_stdout,
> process_stderr => \&read_stderr,
> process_closed => \&cleanup_proc_wheel,
>   );
>
> POE::Kernel->run();
>
> my $time2=time();
> my $usedtime=$time2-$time1;
>
> print"$time2 - $time1 - $usedtime\n";
>
> exit 0;
>
> # Start a number of child processes.  Record their abstractions
> # (wheels) in the session's local storage (its "heap").  All the
> # process events include the IDs of the wheels that have activity.
> # We'll use that later to clean up after finished processes.
>
>
>
> sub start_processes {
>   my $session_storage = $_[HEAP];
>   my $nr;
>   my @servers;
>   my $t;
>   my $command="uptime";
>
>   $nr = @servers = qw(xxx.xxx.xxx.xxx);
>
>   for (1..1) {
>   for ($t=0;$t<$nr;$t++) {
>   my $program="ssh $servers[$t] $command";
>   my $proc_wheel = POE::Wheel::Run->new
> ( Program => "$program",
> StdoutEvent => "process_stdout",
> StderrEvent => "process_stderr",
> CloseEvent => "process_closed",
>   );
>   $session_storage->{$proc_wheel->ID} = $proc_wheel;
>   }
>   }
> }
>
> # Process stdout and stderr from the child process.
>
> sub read_stdout {
>   my ($stdout, $proc_wheel_id) = @_[ARG0, ARG1];
>   print "Wheel $proc_wheel_id stdout: $stdout\n";
> }
>
> sub read_stderr {
>   my ($stderr, $proc_wheel_id) = @_[ARG0, ARG1];
>   print "Wheel $proc_wheel_id stderr: $stderr\n";
> }
>
> # Clean up after a process when it's done.
>
> sub cleanup_proc_wheel {
>   my ($session_storage, $proc_wheel_id) = @_[HEAP, ARG0];
>   delete $session_storage->{$proc_wheel_id};
> }
>