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

suppose one has 2 sessions: session1 session2. Now suppose the only purpose for session2 to remain alive after running its own _start is so that it waits for certain signals from session1. Making a infinite loop is not an option(or is it ?) because it blocks,and never lets session1 signal session2. So what can one do so that it waits for signals ? Thank you

Replies are listed 'Best First'.
Re: POE session remains alive
by merlyn (Sage) on Aug 20, 2007 at 17:11 UTC
    Any session that has registered signal handlers or an alias will remain alive indefinitely. In fact, I've found it hard to make sessions go away!

      Ok i've found a solution,I don't really know if it's how POE was designed to run , but reading the documentation and trying to make it work I just couldn't find any other way. I am sure that there is a "official" way or something,so if someone is kind enough please show it to me.

      use warnings; use strict; use Tk; use POE; POE::Session->create ( inline_states => { _start => sub { my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEA +P ]; # # # _start does important stuff... # # $kernel->yield("some_loop"); }, some_loop => sub { $_[KERNEL]->delay("ev_count",10);#to keep session alive }, } ); $poe_kernel->run(); exit 0;

      I've just tried setting an alias and the session still ran _stop and then I wasn't able to run post on any other state of it

Re: POE session remains alive
by Ultra (Hermit) on Sep 26, 2007 at 13:58 UTC

    In addition to what merlyn had said, you may use

    $kernel->refcount_increment( $session_id, $refcount_name );
    to increase the reference count on you session; this will prevent the Kernel to garbage collect your session;

    this means also that you need to

    $kernel->refcount_decrement($session_id, $refcount_name );
    at some point, when you know the session is not needed anymore; this doesn't mean it will go away immediately, but it will be garbage collected when it doesn't have anything to do

    Dodge This!