[PyKDE] Now tackle dtor strangeness

Hans-Peter Jansen hpj at urpla.net
Tue Jan 28 14:12:00 GMT 2003


On Sunday 26 January 2003 01:16, Phil Thompson wrote:

> > Funny side note: it was enough to fix one of both sub classes this way to
> > prevent attribute errors here. This is pretty undeterministic, and that's
> > exactly the reason, why I don't like this behaviour...
> >
> > Phil, one would expect, that as long as a class exists, its baseclass
> > should exist, either. The same goes for globals in module scope.
>
> The class will exist (because the sub-class keeps a reference to it) but
> that doesn't mean that the reference to the class in (for example) the
> module's dictionary still exists.
>
> The problem is that the order in which a dictionary's elements are deleted
> isn't very deterministic. In your example qEventDict is being removed from
> the module dictionary before the qEvent function is removed. By moving
> qEventDict into the qEvent function you guarantee it will exist whenever
> qEvent is called.
>
> I would guess that the problem would also go away if you played with the
> names of qEvent and qEventDict so that they had hash values that caused
> them to appear in the module dictionary in the opposite order so that
> qEvent was deleted first.

I wasn't able to modify this behaviour with name mangling. OTOH, creating
a separate startup module solved this for me.

For the record: 

If you suffer from attribute exceptions after calling qApp.quit(), and
have defined overloaded event methods in an "all in one" module, try
creating a seperate startup module in order to fix the race between
pythons cleanup and Qt events still delivered. Pythons '-v' option may 
be helpful in this scenario, too.

Pete




More information about the PyQt mailing list