[PyKDE] Changes to Signal/Slot Handling
Giovanni Bajo
rasky at develer.com
Sun Dec 10 12:05:47 GMT 2006
Phil Thompson wrote:
>>> lambda functions are now treated slightly differently and can now be used
>>> as slots.
>> Why can't you simply always incref the slot, be it a lambda, a method or
>> anything else?
>
> I don't trust my understanding of the cyclic garbage collector sufficiently
> well to make what would be a radical change without breaking existing
> applications. It needs more investigation - but handling lambdas was easy and
> relatively risk free.
Why handling lambdas is supposed more risk-free than anyting else? lambdas can
hold an arbitrary number of references with them:
QObject.connect(self.foo, SIGNAL("A"), lambda: self.foo.func(4))
I know you had a special case for methods because you could store a
"weak-method" (the moral equivalent of a bound method but with a weakref to
the object); this allows to effectively *not* hold a reference to the QObject.
But with lambdas, you're basically allowing any reference to be kept in life
by the signal connection, including references to QObjects. What can be
"worse" than that, to require special attention? Surely local functions are
exactly like lambdas; or any kind of callable.
BTW: are the universal slots traversed by the cyclic GC? That's basically all
you probably need to do... Because otherwise, even my small example above is a
loop which is not collectable...
--
Giovanni Bajo
More information about the PyQt
mailing list