Does Python cache the startup module?

B

Baz Walter

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
 
K

kyosohma

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:
['__builtins__', '__doc__', '__name__']


HTH

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top