[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Does Python cache the startup module?

Baz Walter

1/7/2008 6:30:00 PM

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


1 Answer

Mike Driscoll

1/7/2008 7:13:00 PM

0

On Jan 7, 12:30 pm, Baz Walter <baz...@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