[mod_python] [Vampire] Module partially loaded?

Graham Dumpleton grahamd at dscpl.com.au
Fri Jul 1 06:51:05 EDT 2005

If things were working properly, that strictly shouldn't be required,
but I do note that I possibly do the wrong thing in the that I update
the mtime in the cache before reimporting the module. This would be
bad if the import fails as it wouldn't try to keep reloading the module
and would instead use the working one loaded into the cache only. But
then, this could also be good as although it would error on one request,
after that it would use the good one still in the cache until the one
on disk was fixed and modification time updated. I may well have done
it intentionally that way, can't remember. :-)

Either way, this issue shouldn't result in a partly loaded broken
module, although I have some other ideas as to why it might be 


On 01/07/2005, at 8:29 PM, Nicolas Lehuen wrote:

> Maybe you can force reload by touching the module's modified timestamp 
> ?
> Regards,
> Nicolas
> 2005/7/1, Graham Dumpleton <grahamd at dscpl.com.au>:
>> On 01/07/2005, at 7:52 AM, Stephane Bortzmeyer wrote:
>>> I have a Python module which defines several functions and also
>>> includes a bit a code is executed when the module is imported:
>>> do_something()
>>> def function1():
>>>    ...
>>> If do_something() fails (it connects to a database and the database
>>> server may be down), the rest of the module is not executed, 
>>> function1
>>> is not defined but the module stays loaded: further requests just get
>>> a message that there is no function1 defined.
>>> Restarting Apache is the only solution to get rid of the partly 
>>> loaded
>>> module.
>>> It seems a bug to me: if the module cannot be fully loaded because 
>>> the
>>> initialization code fails, the module should not be loaded at all, so
>>> that further attempts have a chance to succeed.
>> I'll do some checking, but modules are imported using:
>>          # Perform the actual import of the module.
>>          try:
>>            execfile(file,module.__dict__)
>>          except:
>>            # Importation of module has failed for some
>>            # reason. If this is the very first import of
>>            # the module, need to discard the cache entry
>>            # entirely else a subsequent attempt to load
>>            # the module will wrongly think it was
>>            # successfully loaded already.
>>            if cache.module is None:
>>              del self._cache[label]
>>            raise
>> Thus, an exception on import is explicitly detected but only
>> for the purpose of ensuring that if this is the first time
>> that the module is being imported that the cache is cleared
>> of the partially constructed entry. If this isn't done then on
>> next import attempt it may think it has been loaded and
>> module reference will be None.
>> In either case, the error is propagated and the failed module
>> should be thrown away.
>> Is the module the error occurs in being explicitly loaded
>> using vampire.importModule() or using the "import" statement
>> and relying on the import hook to call vampire.importModule()
>> for you? Also, does it happen on the first loading of the
>> module or has the module been changed and is it on a reload?
>> Graham
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list