abi3 wheels drift the refcount of None; on Python 3.14 None loses immortality after ~1e9 calls
Cong Nguyen Thanh
nthanhcongaasc at gmail.com
Wed Nov 4 11:18:16 GMT 2026
Hi,
With the PyQt6 cp310-abi3 wheels (6.11.0, and also the latest 6.12.0) on
CPython 3.14.7 (Windows x64), every PyQt6 method that returns None adds +1
to the raw refcount of None, and that +1 is never taken back. Methods that
return other values add nothing; True/False are not affected.
On Python 3.14, None starts at a refcount of 0xC0000000 and stays immortal
only while bit 31 is set, so there is a margin of 2**30 (~1.07e9). After
that many calls, None stops being immortal and the 3.14 interpreter starts
failing its own None checks. Every Python-level __init__ then raises:
TypeError: __init__() should return None, not 'NoneType'
Logging, warnings, pandas etc. all break, and the process stays broken
until restart.
In practice this is reached in under 2 hours by the common pattern
while w.isVisible():
app.processEvents()
since every iteration is +1 (about 160k/s in our application).
My guess is that the abi3 .pyd files are compiled against pre-3.12 Python
headers, where Py_INCREF(Py_None) is a plain ob_refcnt++ that knows nothing
about immortal objects, while 3.14 never decrements immortal objects.
Building the abi3 wheels against Python >= 3.12 headers (still targeting
the 3.10 limited API) should fix it. PyAV 19 and protobuf fixed the same
problem this way.
The attached script shows the +1 per call in a few seconds; run it with
--full to reproduce the TypeError (about 5 minutes).
Output on my machine:
Python 3.14.7, PyQt6 6.11.0, Qt 6.11.0
None refcount at start: low32=0xc0000000 ob_overflow=0
QPoint.setX() None refcount delta per call: +1.00
QObject.setObjectName() None refcount delta per call: +1.00
QApplication.processEvents() None refcount delta per call: +1.00
QPoint.x() [returns int] None refcount delta per call: +0.00
Related CPython issue: https://github.com/python/cpython/issues/158401
Best regards,
Thanh Nguyen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20261104/039fdc15/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyqt6_none_refcount_repro.py
Type: text/x-python
Size: 1647 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20261104/039fdc15/attachment.py>
More information about the PyQt
mailing list