[PyQt] Multithreading, signals, reference counting and crash

Jones, Bryan bjones at ece.msstate.edu
Fri Feb 12 19:57:05 GMT 2016


I'd like to thank Ilya for bringing this to light. I thought I'd worked
around a similar problem, but I now see that I mistakenly assumed Python
semantics where C++ semantics apply. To make sure I understand correctly:

1. If a Python type can converted to a pass-by-value C++ type (int, long,
etc.) then it will be passed as the C++ value through the signal/slot
mechanism, meaning I don't need to retain a Python reference to it to keep
it valid.
2. If a Python type cannot be converted to a pass-by-value C++ type
(string, big int, dict, object, etc.) then a pointer to it will be passed
through the signal/slot mechanism, meaning I must retain a Python reference
until the signal has been delivered to all slots.

However, I do see Qt employing pointers (QFileSystemWatcher's signals emit
const QString&, QLabel::setMovie(QMovie*). Does this imply that the
emitters of these signals can somehow "know" when it's free to destroy the
QString they emitted? Or that developers which use QFileSystemWatcher
should not destroy it until all of its signals have been delivered? This
seems hard to do. How do C++ developers using Qt do this? Perhaps I can
learn from their approach.

Bryan

On Fri, Feb 12, 2016 at 3:43 AM, Phil Thompson <phil at riverbankcomputing.com>
wrote:

> On 11 Feb 2016, at 7:15 pm, Ilya Kulakov <kulakov.ilya at gmail.com> wrote:
> >
> > Phil,
> >
> > How does Qt's automatic unsubscribing in QObject's destructor works then?
> >
> > Best Regards
> > Ilya Kulakov
>
> Unsubscribing to what?
>
> Qt maintains lots of internal data structures about connections, but these
> aren't exposed. As far as I know Qt does not track pointers to QObjects
> when they are sitting in a thread's event queue.
>
> Phil
>
> >> On 12 февр. 2016 г., at 0:30, Phil Thompson <
> phil at riverbankcomputing.com> wrote:
> >>
> >>
> >>> On 11 Feb 2016, at 6:16 pm, Ilya Kulakov <kulakov.ilya at gmail.com>
> wrote:
> >>>
> >>> Phil,
> >>>
> >>> I said I don't know all the details :)
> >>>
> >>> PyQt "controls" both signals and slots. Doesn't it know how many
> receivers are there before it sends?
> >>
> >> The short answer to the question is no. Also, with queued connections,
> a signal may be sitting in an unprocessed event queue for an indeterminate
> amount of time. In network terms, signals are UDP, not TCP.
> >>
> >> Phil
> >
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160212/1f814288/attachment.html>


More information about the PyQt mailing list