[PyQt] [BUG] PyQt5 default behaviour related to sip.setdestroyonexit()
Phil Thompson
phil at riverbankcomputing.com
Tue Dec 15 11:46:58 GMT 2015
> On 14 Dec 2015, at 5:08 p.m., Vladimir Rutsky <rutsky.vladimir at gmail.com> wrote:
>
> Attached example crashes under debug Python.
>
> On Ubuntu 14.04 with debug Python 3.4.3, Qt 5.5.1, PyQt 5.5.1:
>
> $ QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1 python pyqt5_destroy_on_exit_test.py
> Weak ref <weakref at 0x7f8dc000f358; dead> is dead
> Segmentation fault (core dumped)
> $
I can't reproduce the problem.
> On Windows 7 with debug Python 3.4.3, Qt 5.5.1, PyQt 5.5.1 fails
> without additional accessibility configuration.
>
> As far as I understand crash is caused by destructor of
> QAccessibleCache (QtGui module private singleton) which tries to
> destroy connection to QMenu (destroy[QObject] signal) which has been
> already freed by then *but not C++-desctructed*. QMenu object is freed
> by gc after interpreter exit because it's trapped in reference cycle.
> Sip dealloc doesn't call C++-destructor because interpreter is nulled
> and destroy_on_exit is False by default
snip
> If I change default destroy_on_exit behaviour with
> sip.setdestroyonexit(True) everything works correctly. It's not clear
> why objects are not destroyed on exit by default.
"Objects" here means instances of C++ classes. It's because the order in which the dtors are called cannot be predicted and can cause crashes on exit if Qt doesn't like the order.
> Anyway, if objects are not destroyed on exit their memory shouldn't be
> freed too, otherwise code similar to that of the attached example will
> fail.
I don't understand this sentence. There are two "objects" - the C++ class instance and the Python object that wraps it. setdestroyonexit() applies to the C++ class instance. I don't know what you mean by "their memory".
Can you give me a stack trace of the crash?
Phil
More information about the PyQt
mailing list