[PyQt] since SIP 4.10: closures loosing outer variables!

Phil Thompson phil at riverbankcomputing.com
Sat Feb 13 22:08:40 GMT 2010


On Sat, 13 Feb 2010 22:47:35 +0100, Wilbert Berendsen <wbsoft at xs4all.nl>
wrote:
> Hi,
> 
> since my system upgraded SIP to 4.10 (and KDE to 4.4) my own PyKDE4 app 
> Frescobaldi has strange garbage collection issues all over the place,
with 
> error messages like:
> 
> NameError: free variable 'docGroup' referenced before assignment in
> enclosing 
> scope
> 
> It seems that when I connect a local or lambda function to a Qt signal,
the
> 
> function remains alive but it looses the references its outer variables!
> The 
> objects those outer variables point to are still there (they work as
> usual), 
> but they just become unreachable from local or lambda functions. 
> 
> I can circumvent the problem by passing in those outer variables as
default
> 
> arguments, but that is kind of clumsy.
> 
> How come the outer variables are garbage collected but the function
> containing 
> them not? Is this a bug in SIP or PyQt or should I adapt a different
coding
> 
> style? (i.e. without anonymous or local functions) ? ...

Do you have a test case?

Phil


More information about the PyQt mailing list