'reload M' doesn't update 'from M inport *'
Aahz
aahz at pythoncraft.com
Fri Jul 9 11:47:51 EDT 2010
In article <mailman.465.1278680555.1673.python-list at python.org>,
Frederic Rentsch <anthra.norell at bluewin.ch> wrote:
>
>Module M says 'from service import *'.
>Next I correct a mistake in function 'service.f'.
>Now 'service.f' works fine.
>
>I do 'reload (service); reload (M)'.
>The function 'M.f' still misbehaves.
Absolutely!
>'print inspect.getsource (service.f)' and
>'print inspect.getsource (M.f)' shows the same
>corrected code.
>
>'print service.f' and 'print M.f' show different ids.
>
>So I do 'del M; reload (M)'. Nothing changes.
>
>I delete M again and run gc.collect () to really clean house. I reload
>M again and still nothing changes. The id of the reloaded function
>'M.f' is still the same as it was before the purge and so M.f still
>isn't fixed.
>
>I know I have more radical options, such as starting a new IDLE
>window. That would save me time, but I'd like to take the opportunity
>to understand what is happening. Surely someone out there knows.
Take a look at sys.modules to get a better idea of what's happening.
(Maybe someone else will have time to write a longer answer.)
But really, relying on reload() is foolish in the general case because
it's nearly impossible to track down every single reference.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"....Normal is what cuts off your sixth finger and your tail..." --Siobhan
More information about the Python-list
mailing list