[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: connect()'s refcounting behavior seems buggy, and should be documented
From:       Yuya Nishihara <yuya () tcha ! org>
Date:       2022-03-20 6:40:44
Message-ID: 20220320154044.7e345a49 () lemosa
[Download RAW message or body]

On Sat, 19 Mar 2022 23:13:14 -0700, Ben Rudiak-Gould wrote:
> When a bound method is passed to connect(), PySide6 doesn't hold a
> reference to the bound method at all: It extracts its two fields, the
> "self" object and the function, and holds a weak reference to "self"
> (some instance of Widget in your example) and a strong reference to
> the function (Widget.accept).

Yep, PySide's behavior makes sense.

> On Sat, Mar 19, 2022 at 3:44 AM Yuya Nishihara <yuya@tcha.org> wrote:
> > class Widget(QDialog):
> >     def __init__(self, parent=None):
> >         [...]
> >         self.bb.accepted.connect(lambda: self.accept()) # strong ref
> >         self.t = QTimer()
> >         self.t.timeout.connect(self.onTimeout)
> >         self.t.start(100)
> >     [...]
> >
> > def kick():
> >     w = Widget()
> >     w.exec()
> >     print('w should ideally be deleted here')
> >
> > [...]  
> 
> If I understand your example correctly, and PT made the change I think
> he did, it won't affect this example.

My point is if the new PyQt6 behavior were incref-ing the bound method
(i.e. connect(self.accept) did effectively connect(lambda: self.accept()),
this example would demonstrate the new unintended/buggy behavior.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic