Nicolas Lehuen
nicolas.lehuen at gmail.com
Fri Jul 1 06:29:49 EDT 2005
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 >
|