You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Perrin Harkins <pe...@elem.com> on 2003/08/14 15:16:02 UTC

Re: Problem reloading modules

On Thu, 2003-08-14 at 11:43, Jean-Sebastien Guay wrote:
> And I can see in the error_log that $image is still the absolute path
> ("D:/htdocs/images/project/prefix/bob.jpg" in our example) even after
> the change.

I don't see anything wrong with that chunk of code.  If you restart the
server, does it pick up the change?  Is there anything unusual about the
way you call this sub (AUTOLOAD, function ref, etc.)?

Reloading modules is not foolproof.  Perl doesn't actually support it,
so things like Apache::Reload fake it by removing the module from %INC
and making it get compiled again.  This usually works for things in the
symbol table, but people have reported problems in the past with things
that keep references to lexicals (closures) and other somewhat magical
features.  However, your code here looks pretty vanilla and seems like
it should be working fine with Reload.

- Perrin 

Re: Problem reloading modules

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> On Thu, 2003-08-14 at 15:10, Stas Bekman wrote:
> 
>>OK, I've written a proper entry for the man page, Jean-Sebastien can you 
>>please verify that it all works, as I wrote it without testing. Thanks.
>>http://perl.apache.org/docs/2.0/api/Apache/Reload.html#Problems_with_Scripts_Running_with_Registry_Handlers_that_Cache_the_Code
> 
> 
> Thanks Stas!  I think you have a little mistake here:
> 
> @EXPORT = qw(set_colour);
> 
> That should be
> 
> @EXPORT = qw(colour);

Thanks, committed!



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Problem reloading modules

Posted by Stas Bekman <st...@stason.org>.
> Perrin Harkins wrote:
> 
>>If you're interested
>>in working on it, we could discuss possible approaches on the list and
>>review your patch.
> 
> 
> In a week or so I'll have a bit more free time, and I might try
> implementing it. I'll start by reading up on mod_perl internals... :-)

I'd suggest a different approach. Write a subclass of the registry and if it 
gains popularity we will merge it in. And you don't really need to read on 
mod_perl internals to do that. Just learn the ModPerl/RegistryCooker guts ;)


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
> However, there will always be things that Apache::Reload doesn't
> handle.  For example, you might import functions from one module into
> another module, as opposed to importing into a Registry script.

Well, making a given module aware of who imported it (whether it's a
module or a Registry script) would solve that. But again, I don't know
how complicated that would be; I'll have to read up when I try doing it.


> My
> advice is to avoid importing things at all, but I know that many
people
> really love importing and will not want to give it up.

I'm one of them, at least with our present module hierarchy. But I
understand your point of view too.


J-S



Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 15:33, Jean-Sebastien Guay wrote:
> In a week or so I'll have a bit more free time, and I might try
> implementing it. I'll start by reading up on mod_perl internals... :-)

Actually, all you need to read is the code for Apache::Registry or
ModPerl::Registry (depending on which you are using) and the code for
Apache::Reload.  These are all pure perl modules.

However, there will always be things that Apache::Reload doesn't
handle.  For example, you might import functions from one module into
another module, as opposed to importing into a Registry script.  My
advice is to avoid importing things at all, but I know that many people
really love importing and will not want to give it up.

- Perrin

Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
Stas Bekman wrote:
> > OK, I've written a proper entry for the man page, Jean-Sebastien can
you
> > please verify that it all works, as I wrote it without testing.

Great work Stas, you're quick :-)  Other than the little mistake Perrin
pointed out, the suggested change works.


Perrin Harkins wrote:
> If you're interested
> in working on it, we could discuss possible approaches on the list and
> review your patch.

In a week or so I'll have a bit more free time, and I might try
implementing it. I'll start by reading up on mod_perl internals... :-)


Thanks for your help,

J-S



Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 15:10, Stas Bekman wrote:
> OK, I've written a proper entry for the man page, Jean-Sebastien can you 
> please verify that it all works, as I wrote it without testing. Thanks.
> http://perl.apache.org/docs/2.0/api/Apache/Reload.html#Problems_with_Scripts_Running_with_Registry_Handlers_that_Cache_the_Code

Thanks Stas!  I think you have a little mistake here:

@EXPORT = qw(set_colour);

That should be

@EXPORT = qw(colour);

- Perrin

Re: Problem reloading modules

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Perrin Harkins wrote:
> 
>> On Thu, 2003-08-14 at 14:29, Jean-Sebastien Guay wrote:
>>
>>>> I'm asking you to try it and see if it works.
>>>
>>>
>>> Ok, I tried it and it works.
>>
>>
>>
>> I guess we need to add this to the docs: Apache::Reload will have
>> problems if you import subs from a module you are trying to reload.
> 
> 
> The problem is described here (and one of the solutions is to touch the 
> file as Perrin has mentioned the other is covered in that URL)
> 
> http://marc.theaimsgroup.com/?l=apache-modperl&m=105330639304103&w=2
> 
> I think I have planned to add this to the docs, but didn't get to it 
> yet, I'll try to do that shortly.

OK, I've written a proper entry for the man page, Jean-Sebastien can you 
please verify that it all works, as I wrote it without testing. Thanks.
http://perl.apache.org/docs/2.0/api/Apache/Reload.html#Problems_with_Scripts_Running_with_Registry_Handlers_that_Cache_the_Code


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Problem reloading modules

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> On Thu, 2003-08-14 at 14:29, Jean-Sebastien Guay wrote:
> 
>>>I'm asking you to try it and see if it works.
>>
>>Ok, I tried it and it works.
> 
> 
> I guess we need to add this to the docs: Apache::Reload will have
> problems if you import subs from a module you are trying to reload.

The problem is described here (and one of the solutions is to touch the file 
as Perrin has mentioned the other is covered in that URL)

http://marc.theaimsgroup.com/?l=apache-modperl&m=105330639304103&w=2

I think I have planned to add this to the docs, but didn't get to it yet, I'll 
try to do that shortly.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 14:29, Jean-Sebastien Guay wrote:
> > I'm asking you to try it and see if it works.
> 
> Ok, I tried it and it works.

I guess we need to add this to the docs: Apache::Reload will have
problems if you import subs from a module you are trying to reload.

> The file that imports it is not a module, it's the actual script.

Apache::Registry?  Just do a touch on the script file and Registry will
reload it.  You could hack your own Apache::RegistryNG subclass that
would just reload everything when Apache::Reload triggers, but it's
probably not worth it.

- Perrin




Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 15:01, Jean-Sebastien Guay wrote:
> Could something in Apache::Registry be implemented to integrate it
> better with Apache::Reload? Something along the lines of keeping track
> of which modules a certain script use()s, and at request time, checking
> if Apache::Reload has reloaded one of those since the last request and
> if so, reload the script itself?

It's somewhat tricky to know what modules you've imported from.  Maybe
through overloading use().  The thing is, I don't use Registry or
Apache::Reload so I don't have much motivation to do it.  (I just
restart my server, since it only takes a second.)  If you're interested
in working on it, we could discuss possible approaches on the list and
review your patch.

- Perrin

Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
Perrin,

> Apache::Registry?  Just do a touch on the script file and Registry
will
> reload it.

OK, thanks.

> You could hack your own Apache::RegistryNG subclass that
> would just reload everything when Apache::Reload triggers, but it's
> probably not worth it.

Could something in Apache::Registry be implemented to integrate it
better with Apache::Reload? Something along the lines of keeping track
of which modules a certain script use()s, and at request time, checking
if Apache::Reload has reloaded one of those since the last request and
if so, reload the script itself? That would remove the confusion, and
make Apache::Reload's work more transparent, IMO.


Anyways, for now I will do it as you suggested. Once more, thanks for
the help.

J-S



Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
> I'm asking you to try it and see if it works.

Ok, I tried it and it works.


> A possible solution if that is the problem is to make all the modules
> that import it reload as well.  You can do that with a touch file.

The file that imports it is not a module, it's the actual script. No
other file (that is running currently) needs that sub. Can I get
Apache::Reload to reload the script itself?


Thanks for your help,

J-S



Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 14:04, Jean-Sebastien Guay wrote:
> > Try doing a fully-qualified sub call instead of importing.
> 
> Err, that would actually be a pretty massive change to my codebase.
> Changing all the <somesub> calls to Hybride::Module::<somesub> would be
> a pain, not to mention too much typing. There has to be another
> solution, isn't there?

I'm asking you to try it and see if it works.

A possible solution if that is the problem is to make all the modules
that import it reload as well.  You can do that with a touch file.

- Perrin

Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
Perrin,

> > use Hybride::Projects qw(getImage <other imports>);
>
> I think that's the problem.  You are creating an alias to the sub
here,
> and when it gets reloaded the alias is still pointing to an old
version.

Actually, I just saw that the sub is exported in the EXPORT section of
the Projects module, not the EXPORT_OK section, and is imported with

use Hybride::Projects;

Sorry about that, my mistake... But the sub is still not getting
reloaded.


> Try doing a fully-qualified sub call instead of importing.

Err, that would actually be a pretty massive change to my codebase.
Changing all the <somesub> calls to Hybride::Module::<somesub> would be
a pain, not to mention too much typing. There has to be another
solution, isn't there?


Thanks,

J-S



Re: Problem reloading modules

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-14 at 13:41, Jean-Sebastien Guay wrote:
> > Is there anything unusual about the
> > way you call this sub (AUTOLOAD, function ref, etc.)?
> 
> Not at all. It is imported with
> 
> use Hybride::Projects qw(getImage <other imports>);

I think that's the problem.  You are creating an alias to the sub here,
and when it gets reloaded the alias is still pointing to an old version.

Try doing a fully-qualified sub call instead of importing.

- Perrin

Re: Problem reloading modules

Posted by Jean-Sebastien Guay <je...@hybride.com>.
Hi Perrin,

> I don't see anything wrong with that chunk of code.  If you restart
the
> server, does it pick up the change?

Yes.


> Is there anything unusual about the
> way you call this sub (AUTOLOAD, function ref, etc.)?

Not at all. It is imported with

use Hybride::Projects qw(getImage <other imports>);

and the file in which the sub is located is called Projects.pm, in a
directory Hybride, whose parent directory (D:/htdocs) is added to my
@INC by using 'use libs qw(D:/htdocs)' in my startup.pl file AND
'PerlSwitches -ID:/htdocs' in my httpd.conf (I just wanted to make
sure... :-). I can see with perl-status that my @INC is correctly set to
pick up the module, and that the module itself is listed in %INC with
its absolute path on my filesystem, so that should be right.

I get this in my error_log when I refresh the page that runs the CGI
script that uses the sub:

Apache::Reload: Checking mtime of Hybride/Projects.pm
Subroutine listProjects redefined at D:/htdocs/Hybride/Projects.pm line
33.
Subroutine validProject redefined at D:/htdocs/Hybride/Projects.pm line
49.
Subroutine getImage redefined at D:/htdocs/Hybride/Projects.pm line 68.
Subroutine getProjectAbbreviation redefined at
D:/htdocs/Hybride/Projects.pm line 92.
Apache::Reload: process 2392 reloading Hybride/Projects.pm

I believe those warnings are normal since the module is being reloaded
and the subs are being replaced in memory, right? So that tells me that
the module is reloaded. However, the old code is still being used.


> However, your code here looks pretty vanilla and seems like
> it should be working fine with Reload.

I agree. Is there anything else I can check to make sure I'm not missing
anything obvious?


Thank you,

J-S