Re: Question on Reloading Modules in POE server
POE's "odd" double-indirection means that only POE::Session holds
references to your code:
POE::Session->create(
{
inline_states => {
event_name => \&your_code,
...,
}
}
);
Everything else refers to handlers by event name.
Reloading the code isn't enough for inline_states since the session is
still referring to the old handlers. In this case, a session must use
POE::Kernel's state() to redefine its event handlers in terms of the
new code.
From POE's perspective there should be no additional work for object-
or package-based handlers.
--
Rocco Caputo - [EMAIL PROTECTED]
On Oct 27, 2008, at 10:56, ty wrote:
I have a POE server that spawns some sessions that use
POE::Component::Generic. Each of these sessions act as a separate
tool in the server. From time to time, I have to make changes to a
module that is used by one of the sessions. It requires me to restart
the server now so that the new changes are reflected. It would be
nice if there was a way to tell the session to reload the module like
it is possible in mod_perl with various apache modules. I came across
a post on this group in 2005 titled Unuse Modules, but this was
looking at the problem from getting them out of the system not
reloading. Module::Refresh seems to be a possible solution. However,
I wanted to know if anyone has successfully done something like this
in the context of POE running in a persistent environment?
Best Regards
Ty
Re: Question on Reloading Modules in POE server
>From the keyboard of ty [27.10.08,07:56]:
> I have a POE server that spawns some sessions that use
> POE::Component::Generic. Each of these sessions act as a separate
> tool in the server. From time to time, I have to make changes to a
> module that is used by one of the sessions. It requires me to restart
> the server now so that the new changes are reflected. It would be
> nice if there was a way to tell the session to reload the module like
> it is possible in mod_perl with various apache modules. I came across
> a post on this group in 2005 titled Unuse Modules, but this was
> looking at the problem from getting them out of the system not
> reloading. Module::Refresh seems to be a possible solution. However,
> I wanted to know if anyone has successfully done something like this
> in the context of POE running in a persistent environment?
>
> Best Regards
>
> Ty
Reloading an entire Module can be icky if in addition to undefining the
%INC entry you need to undefine the entire symbol table (e.g. to get rid
of garbage accumulated in that namespace), in which case objects of that
package get re-blessed into the __ANON__ package.
If you just have to modify methods of a class or functions of a module
or package, you could go with AutoReloader by yours truly, which is a
drop-in replacement for AutoLoader and designed for just your type of
apps in mind (see http://search.cpan.org/search?query=AutoReloader
and http://perlmonks.org/?node_id=600805 ).
Of course that means splitting up your module into separate files as
e.g. POSIX in the core distribution.
cheers
0--gg-
--
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\/
/\_¯/(q/
\__(m.·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}
Re: Question on Reloading Modules in POE server
On Mon, Oct 27, 2008 at 07:56:01AM -0700, ty wrote: > I have a POE server that spawns some sessions that use > POE::Component::Generic. Each of these sessions act as a separate > tool in the server. From time to time, I have to make changes to a > module that is used by one of the sessions. It requires me to > restart the server now so that the new changes are reflected. It > would be nice if there was a way to tell the session to reload the > module like it is possible in mod_perl with various apache modules. > I came across a post on this group in 2005 titled Unuse Modules, but > this was looking at the problem from getting them out of the system > not reloading. Module::Refresh seems to be a possible solution. > However, I wanted to know if anyone has successfully done something > like this in the context of POE running in a persistent environment? Haven't tried it and have no experience with Module::Refresh. (Stop reading now, if you like. :) That said, it seems like it'd be possible, with extreme care. Some things that you'd have to be careful with - variable reinitialization - BEGIN/END/etc blocks - class redefinitions It seems likely to me that reloading a module would only work if you've written it to expect to be reloaded, and/or if the changes made affect only certain things. I looked at the Module::Refresh, Apache::StatINC, and Module:: Reload docs. The last one mentions this caveat: A growing number of pragmas (base, fields, etc.) assume that they are loaded once only. When you reload the same file again, they tend to become confused and break. If you try it and get it to work, I, for one, would be interested in reading about your experiences. I haven't done much with POE yet, but it's on the horizon at work, and one of the things I expect to want to do is have a long-running server process that can reload code if it changes. Hmmm ... which actually brings up another idea. Have you looked at PoCo::Generic (or similar ideas)? POE::Component::Generic is a POE component that provides a non-blocking wrapper around any object. It works by forking a child process with POE::Wheel::Run and creating the object in the child process. Method calls on the object are then serialised [sic] and sent to the child process to be handled by the object there. The returned value is serialised [sic] and sent to the parent process, where it is posted as a POE event. If you create the session in a child, then you can update the object definition, and then throw away the old child and start a new one. Hope that helps. -- Larry
