For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > March 2008 > calling $poe_kernel more than once









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 calling $poe_kernel more than once
Yuri Shtil

2008-03-14, 8:13 pm

What will happen if $poe_kernel->run called more than once?

If this is bad, is there a way to detect that the loop is already active.

-- Yuri
Matt Sickler

2008-03-14, 8:13 pm

Go right ahead. run() doesn't return until the POE loop completely
shutsdown, so its somewhat pointless.
IIRC, the wiki has an example where it does make sense.

On Fri, Mar 14, 2008 at 3:54 PM, Yuri Shtil <yuris@juniper.net> wrote:

> What will happen if $poe_kernel->run called more than once?
>
> If this is bad, is there a way to detect that the loop is already active.
>
> -- Yuri
>


Yuri Shtil

2008-03-14, 8:13 pm

What if it is called while in the POE loop?

Matt Sickler wrote:
> Go right ahead. run() doesn't return until the POE loop completely
> shutsdown, so its somewhat pointless.
> IIRC, the wiki has an example where it does make sense.
>
> On Fri, Mar 14, 2008 at 3:54 PM, Yuri Shtil <yuris@juniper.net
> <mailto:yuris@juniper.net>> wrote:
>
> What will happen if $poe_kernel->run called more than once?
>
> If this is bad, is there a way to detect that the loop is already
> active.
>
> -- Yuri
>
>

Phil Whelan

2008-03-14, 8:13 pm

Hi Yuri,

[color=darkred]
> What if it is called while in the POE loop?


I think it may tear a hole in the space-time continuum!

I'd be interested to see how you've structured your code to get this
to be called twice. I usually just do the following...

<set up sessions to run here>

POE::Kernel->run;
exit;

Cheers,
Phil

On Fri, Mar 14, 2008 at 4:49 PM, Yuri Shtil <yuris@juniper.net> wrote:
> What if it is called while in the POE loop?
>
>
> Matt Sickler wrote:
>
>
>




--
Mobile: +1 778-233-4935
Website: http://philw.co.uk
Skype: philwhelan76
Email : phil123@gmail.com
iChat: philwhln@mac.com
Yuri Shtil

2008-03-16, 11:12 pm

Hi Phil,

I have sketched an object module that hides the POE under the hood. The
user "loads" the object and then calls the method run (!surprise!).
The run method in turn calls $poe_kernel->run. The problem may arise
when the user creates more similar objects in callbacks/event handlers
and calls the run on them.
The whole idea was to make the user of the objects POE ignorant.
In any case, if calling $poe_kernel->run from the POE loop may destroy
the universe, the question is:
how to detect that the POE loop is active?

Phil Whelan wrote:
> Hi Yuri,
>
>
>
>
>
> I think it may tear a hole in the space-time continuum!
>
> I'd be interested to see how you've structured your code to get this
> to be called twice. I usually just do the following...
>
> <set up sessions to run here>
>
> POE::Kernel->run;
> exit;
>
> Cheers,
> Phil
>
> On Fri, Mar 14, 2008 at 4:49 PM, Yuri Shtil <yuris@juniper.net> wrote:
>
>
>
>
>

Phil Whelan

2008-03-16, 11:13 pm

Hi Yuri,

Sounds like an interesting implementation of POE usage. I have no
experience of using POE runs within a larger application. I'll have to
try that out.

I haven't tested this myself, but you could try calling...

POE::Kernel->get_active_session()

If there is no active session, then I guess POE would not be running.

Cheers,
Phil

On Sun, Mar 16, 2008 at 7:37 PM, Yuri Shtil <yuris@juniper.net> wrote:
> Hi Phil,
>
> I have sketched an object module that hides the POE under the hood. The
> user "loads" the object and then calls the method run (!surprise!).
> The run method in turn calls $poe_kernel->run. The problem may arise
> when the user creates more similar objects in callbacks/event handlers
> and calls the run on them.
> The whole idea was to make the user of the objects POE ignorant.
> In any case, if calling $poe_kernel->run from the POE loop may destroy
> the universe, the question is:
> how to detect that the POE loop is active?
>
>
>
> Phil Whelan wrote:
>




--
Mobile: +1 778-233-4935
Website: http://philw.co.uk
Skype: philwhelan76
Email : phil123@gmail.com
iChat: philwhln@mac.com
Matt Cashner

2008-03-17, 5:04 am

I just took a brief diving trip through the source. Looks like that
the various kernel bits check to see if $poe_kernel is live just to
avoid setup costs. Even if there is a live kernel, it will attempt to
launch into another core loop. I'm not sure a space-time continuum
breach would occur but you do run the risk of having the Stay-Puft
marshmallow man trash your city.

There are two paths in this forest. First, the kernel can be patched
to avoid that kind of multiple spin up. Personally, I find that
artificially limiting. I'm not sure why one would want to do any of
this but I've learned over the years that the POE community comes up
with strange ways to use pretty much every bug or odd side effect
that's ever been found in the core.

Second, in your magic POE wrapping api, you can use POE::API::P to
determine the state of the kernel. I've got a is_running() method in
there that you can either use via my module or rip out and use with
credit. Yay for the bsd license :) Using the module would help me know
that it still works though :)

I'm just guessing here but I think your best ROI is the second option.
Just my suggestion though :)

--
Matt Cashner
mattcashner@mac.com
http://mattcashner.com

Robert Landrum

2008-03-17, 7:53 pm

Matt Cashner wrote:
> Second, in your magic POE wrapping api, you can use POE::API::P to
> determine the state of the kernel. I've got a is_running() method in
> there that you can either use via my module or rip out and use with
> credit. Yay for the bsd license :) Using the module would help me know
> that it still works though :)


Or third, you could track the state of POE inside the object that is
wrapping POE.

return if $self->{is_running};
$self->{is_running} = 1;
$poe_kernel->run;

Or am I missing something obvious?

Rob
Yuri Shtil

2008-03-17, 7:53 pm

Your solution assumes only one object wrappping POE.


Robert Landrum wrote:
> Matt Cashner wrote:
>
> Or third, you could track the state of POE inside the object that is
> wrapping POE.
>
> return if $self->{is_running};
> $self->{is_running} = 1;
> $poe_kernel->run;
>
> Or am I missing something obvious?
>
> Rob

Matt Cashner

2008-03-17, 7:53 pm


On Monday, March 17, 2008, at 12:38PM, "Yuri Shtil" <yuris@juniper.net> wrote:

>Your solution assumes only one object wrappping POE.


More importantly, it assumes that poe is only ever run once. It is very possible to run poe, complete whatever you want to do, shut poe down and for whatever reason spin it all back up again. There's no way for the wrapper class to know that poe has shutd
own and is now not active unless it talks to poe internals somehow.

--
Matt Cashner
mattcashner@mac.com
http://mattcashner.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com