Does Python cache the startup module?

kyosohma at gmail.com kyosohma at gmail.com
Mon Jan 7 14:13:29 EST 2008


On Jan 7, 12:30 pm, Baz Walter <baz... at googlemail.com> wrote:
> Hello
>
> I remember reading somewhere (probably this list) that python may cache the
> module that starts a program (e.g. 'main.py'). I'm asking because I have found
> that this can sometimes cause problems when making small edits to the module.
> For instance, in my current module I changed the name of the main gui widget.
> When I ran the program, the program started to leak memory like a sieve. I then
> changed the name back again, and the problem went away. This looks very much
> like some sort of weird caching behaviour to me.
>
> I've tried deleting the .pyc file and even re-booting, but I can't make the
> problem go away!
>
> Can anyone confirm that this caching happens? And if so, is it documented
> anywhere?
>
> TIA

You can run a dir() in the GUI IDLE or the command line IDLE and see
what's currently "cached", so to speak. In the GUI IDLE, you can
"flush" it out by going to the Shell menu and choosing Restart Shell.

It should only display the following after a restart:

>>> dir()
['__builtins__', '__doc__', '__name__']


HTH

Mike




More information about the Python-list mailing list