[BangPypers] reload modules at the start of an app..

Vishal vsapre80 at gmail.com
Sat Jul 14 10:40:34 CEST 2012


On Sat, Jul 14, 2012 at 1:32 PM, Vishal <vsapre80 at gmail.com> wrote:

> 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.
>
>
One of the biggest cons is that, this approach has to potential to almost
'double' your app start up time. However for small (say upto 10 modules of
each not more than 50K), this approach works out fine.

-- 
Thanks and 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