[BangPypers] reload modules at the start of an app..
Vishal
vsapre80 at gmail.com
Sat Jul 14 10:02:43 CEST 2012
Hi,
Wanted to find what you think about reloading modules just before app
start. This is to take care of repeated debugging sessions inside IDEs,
where changed 'py' files are not imported automatically by the IDE.
One simple way of having everything reloaded is to do:
import sys
for mod in sys.modules.keys():
try:
result = reload(__import__(mod))
except:
pass
the 'result' is string that gets returned from reload(). so we simply
consume it and dont allow it to be sent to stdout, otherwise you will get a
long print out of reloaded modules.
reload() will throw exceptions when it cannot reload a module, but these
are again silenced above.
This snippet will allow reloading of all modules that have been loaded till
this point. So it should be at the end of all module imports in your
application...ideally just before the 'main' function is called in your app.
Any views on this approach? Pros/Cons/Better Approaches... etc
Best regards,
Vishal Sapre
---
Please DONT print this email, unless you really need to. Save Energy &
Paper. Save the Earth.
More information about the BangPypers
mailing list