[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.python

Re: Does Python cache the startup module?

Baz Walter

1/7/2008 7:21:00 PM

Guilherme Polo <ggpolo <at> gmail.com> writes:
> Uhm.. this didn't make much sense. If you say the module is cached,
> then supposing you did a minor edit, and then supposing because it is
> cached your application wouldn't detect the change, then I don't see
> the connection with memory leak.
>
> Bring some concrete proof.

Thanks for your reply.

It's hard to supply an example for this, since it is local to the machine I am
using. The startup module would look something like this:

#!/usr/local/bin/python

if __name__ == '__main__':

import sys
from qt import QApplication, QWidget

application = QApplication(sys.argv)
mainwindow = QWidget()
application.setMainWidget(mainwindow)
mainwindow.show()
sys.exit(application.exec_loop())

If I change the name 'mainwindow' to 'mainwidget', the widget it refers to does
not get destroyed; when I change it back again, it does get destroyed.
Otherwise, the program runs completely normally.


2 Answers

John Machin

1/7/2008 8:23:00 PM

0

On Jan 8, 6:21 am, Baz Walter <baz...@googlemail.com> wrote:
> Guilherme Polo <ggpolo <at> gmail.com> writes:
>
> > Uhm.. this didn't make much sense. If you say the module is cached,
> > then supposing you did a minor edit, and then supposing because it is
> > cached your application wouldn't detect the change, then I don't see
> > the connection with memory leak.
>
> > Bring some concrete proof.
>
> Thanks for your reply.
>
> It's hard to supply an example for this, since it is local to the machine I am
> using. The startup module would look something like this:
>
> #!/usr/local/bin/python
>
> if __name__ == '__main__':
>
> import sys
> from qt import QApplication, QWidget
>
> application = QApplication(sys.argv)
> mainwindow = QWidget()
> application.setMainWidget(mainwindow)
> mainwindow.show()
> sys.exit(application.exec_loop())
>
> If I change the name 'mainwindow' to 'mainwidget', the widget it refers to does
> not get destroyed; when I change it back again, it does get destroyed.
> Otherwise, the program runs completely normally.

If you execute that stuff inside a function (see below) instead of in
global scope, do you get the same effect?

if __name__ == '__main__':
import sys

def main():
from qt import QApplication, QWidget
application = QApplication(sys.argv)
mainwindow = QWidget()
application.setMainWidget(mainwindow)
mainwindow.show()
result = application.exec_loop())
return result

sys.exit(main())

Baz Walter

1/7/2008 9:18:00 PM

0

John Machin <sjmachin <at> lexicon.net> writes:
> If you execute that stuff inside a function (see below) instead of in
> global scope, do you get the same effect?

Thanks for your reply.

No, running it inside a function means I can't rely on python to garbage
collect, so there will be widgets left over whether I've changed names or not.

See Frederik Lundh's last message to see what's really happening.