weakref, memory management and execution slow down in PyQt4

kjs bfb at riseup.net
Sun Sep 7 22:39:20 CEST 2014



Michael Torrie:
> On 09/07/2014 01:11 PM, kjs wrote:
>> Thanks for the advice. I commented out the graph generation and PyQt call
>>
>>>>> self.app.processEvents()
>>
>> where in the class __init__
>>
>>>>> self.app = QtGui.QApplication(sys.argv)
>>
>> This stopped the weakref proliferation. All other objects grow and
>> shrink in number as expected.
> 
> Can you make an absolute minimal example with no widgets save the graph
> itself?  You could then go to the PyQt folks with that.  Could be a bug,
> or could be an improper use of something by your code.  This is one of
> the problems with using Qt in other languages: it's not a perfect fit
> for Python's object model as it is C++-based.  So you have to think like
> a C++ programmer, and you might have to manage some resources manually,
> unlike normal Python objects which for the most part take care of
> themselves.
> 

The code is minimal[0]. The only other widgets are a start button that
fires off the plotting and a stop button that calls sys.exit().

Lines 112-114 appear to be causing the weakref proliferation.

I do not doubt that I could be using PyQt4 incorrectly. I'll send a
message to the pyqt mailing list as well.

> Also you could try a minimal example using PySide instead of PyQt and
> see if that also manifests the leak.  If so, then the problem could be
> in Qt itself.  Though I suspect the problem is some kind of impedance
> mismatch between C++ and Python.
> 

Thanks much,
Kevin

[0]
https://github.com/kevinjos/kaggle-aes-seizure-prediction/blob/master/explore.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x8A61431E.asc
Type: application/pgp-keys
Size: 11239 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20140907/457ad8da/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20140907/457ad8da/attachment.sig>


More information about the Python-list mailing list