On Fri, Jun 06, 2003 at 01:23:51PM +0200, Laurent Perez wrote:
> Hi
> 
> I'm trying to let a session stay in 'background' while another session is 
> kept in progress in 'foreground'.
> Here's a code snippet I wrote :
> 
> (this code is called from my main session, st_* have been defined to point 
> to correct subs)
> 
> my $idling_task = POE::Wheel::Run->new(
>                 Program => \&keep_idle_sess,
[...]
>                 ) or die;
>                 $_[HEAP]->{task}->{ $idling_task->ID } = $idling_task;
[...]
> sub keep_idle_sess {
>     POE::Session->new (
>     _start => \&keep_idle,
>      keep_hello => \&keep_hello,
>     ) or die;
> }
[...]
> 
> My problem is that the delay method doesn't get started. Instead, I'm 
> receiving a hello, then st_cl_idle confirmation that the child process did 
> exit (I guess that's what I should have expected...).
> 
> What I want is to run that keep_hello sub looping itself outside my main 
> poe session because it contains blocking operations freezing my main 
> process for few seconds on every loop (the print hello is just an example). 
> I was hoping creating a session from a Wheel::Run object would keep the 
> session alive but I guess not :/
> 
> Can anyone help me ?

POE::Wheel::Run follows the UNIX idiom of pipe/fork/exec to run and
interact with a detached process.

The detached process may run a Perl function, but the process will exit
as soon as that function returns.

It would be better if keep_idle_sess() ran its own loop and only
returned when it was completely done.  For instance:

  sub keep_idle_sess {
    while (1) {
      print "hello !!\n";
      sleep(20);
    }
  }

We can get away with this because it's running in a completely different
process.

Your session is not kept alive because POE::Wheel::Run finishes with the
child process.  It should work better with an updated keep_idle_sess().

-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/

Reply via email to