[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Unable to weakreference pyqtBoundSignal
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2017-10-09 17:11:58
Message-ID: D352C3AC-09F8-41AD-91CE-025A2FB308B0 () riverbankcomputing ! com
[Download RAW message or body]
On 29 Sep 2017, at 1:57 pm, Kyle Altendorf <sda@fstab.net> wrote:
> On 2017-09-29 04:58, Phil Thompson wrote:
> > On 29 Sep 2017, at 4:22 am, Kyle Altendorf <sda@fstab.net> wrote:
> > > TypeError: cannot create weak reference to 'PyQt5.QtCore.pyqtBoundSignal' \
> > > object Are pyqtBoundSignals intentionally not weak referenceable? If not, \
> > > could it be? Example and output:
> > > https://gist.github.com/altendky/9f942709dfc2f33019723ffff43260b1
> > > Since I already had it open:
> > > https://docs.python.org/3/extending/newtypes.html#weakref-support
> > They aren't because I don't really see the point. Bound signals only
> > exist during the period of an emit(), connect() or disconnect().
> > Having said that, bound methods are weak referenceable.
>
> My use case was that I am creating functions dynamically to connect as slots and
> wanted hold the signal/slot pairs in a WeakKeyDictionary I could later use to
> disconnect them. Instead I just apply the same logic to get the same signals
> again to disconnect. Using the slot as a weak key just seemed a bit more direct.
>
> But perhaps I am misunderstanding something. You say the the bound signal only
> exists _during_ an emit/connect/disconnect? I'm not sure what's going on there.
> I explored a little but didn't find anything enlightening. The id() of the signal
> is the same when accessed repeatedly and inspect.is{data,method,member}descriptor()
> all return False in my checks.
>
> https://gist.github.com/altendky/7096674b424af3ed8d80e47a41af3169
>
> If you have time to explain a little I would be interested to learn.
You are (perhaps understandably) misreading the str() of a bound signal. The address \
embedded in the string is the id() of the bound object (ie. id(o)). If you print the \
id() of a and b you will see they are different.
Regarding inspect, *unbound* signals are descriptors, not bound ones.
Phil
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic