Does Python cache the startup module?

John Machin sjmachin at lexicon.net
Mon Jan 7 21:22:31 CET 2008


On Jan 8, 6:21 am, Baz Walter <baz... at 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())



More information about the Python-list mailing list